有一个asp.net页面,由三个框架组成,左边的框架是一些链接,右边的框架是显示的页面,在右边提供将DataGrid的内容动态生成Excel文件后下载,但下载了文件后,左边的链接就失效了,点击左边的链接不会在右边显示新的页面,请问是什么原因,该如何解决?
代码如下:
     leftFrame.aspx:        ......
        <TR>
        <TD onmouseover="this.className='tdfocus'" onmouseout="this.className='tdnml'">
        <P><IMG height="7" src="../images/cm.gif" width="14"><asp:hyperlink NavigateUrl="../Right/Gsxx/Main_GsxxQuery.aspx" target="mainFrame" Runat=server>&nbsp;工伤统计&nbsp;</asp:hyperlink></P> </TD>
</TR> <TR> <TD onmouseover="this.className='tdfocus'" onmouseout="this.className='tdnml'"> <P><IMG height="7" src="../images/cm.gif" width="14"><A href="../Right/Lkgl/Main_LkglQuery.aspx" target="mainFrame">&nbsp;离矿信息&nbsp;</A></P> </TD>
</TR>
      ...

解决方案 »

  1.   

    右边的框架执行以下代码:
          private void lkbExportToExcel_Click(object sender, System.EventArgs e)
    {
    SaveDataToExcel();
    } public void SaveDataToExcel()
    {
    Response.Clear(); 
    Response.Buffer= true; 
    //Response.Charset="GB2312";    
    Response.Charset = "utf-8";
    Response.AppendHeader("Content-Disposition","attachment;filename=Excel Report.xls"); 
    //Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
    this.EnableViewState = false;    
    System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); 
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
    this.ClearControls(this.dgdQueryResult);
    this.dgdQueryResult.RenderControl(oHtmlTextWriter); 
    Response.Write(oStringWriter.ToString());
    Response.End(); }
    执行了SaveDataToExcel就出现了左边框架的链接无效的问题,请高手帮着看看。
      

  2.   

    确实存在这个问题,只有javascript脚本来解决了:
    mainFrame.location.href = "...";
      

  3.   

    我当时的情况时把attachment换成inline就解决了
    attachment意思是强制提示下载框,不过你这个比较麻烦,因为xls是ie认识的文件格式
    换成inline会自动打开
    这个问题困扰我很久了