按钮禁用但未启用

时间:2012-06-13 15:53:12

标签: asp.net

当我点击btn控制使用javascript禁用btn然后btn点击事件调用。 在btn click事件中我编写代码,它为我使用方法提供excel / pdf格式的报告 ExportToHttpResponse(ExportFormatType.Excel,Response,true,“Report Name”)在这个方法之后给了我异常 当我写btn.enable = true时,或者最后阻止;或者使用javascript然后不执行。 异常是无法计算表达式,因为代码已优化或本机框位于调用堆栈之上

即。我必须在生成报告时启用btn。 当这个方法被执行时ExportToHttpResponse()我得到了报告 所以在这个方法之后我必须启用btn控件

protected void Page_Load(object sender, EventArgs e)
{
    btnExcel.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnExcel, null) + ";");
}


protected void btnExcel_Click(object sender, EventArgs e)
{
   view_report();
    try
    {
       Rpt.ExportToHttpResponse(ExportFormatType.Excel, Response, true, " Reportname");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        ex = null;
    }
    finally
    {                  
       btnExcel.Enabled = true;
        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJSFunction", "myEnablefunction()", true);
    }
}

1 个答案:

答案 0 :(得分:0)

如果您直接写入Response,则所有asp.net结构都已损坏,因此您无法更改控件的属性,因为您已经干扰了asp.net的“自然”渲染。如果导出过程中出现错误,则页面会中断。

相关问题