本文介绍了按钮禁用但不启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击btn控件时,使用javascript禁用btn,然后btn单击事件调用.
在btn click事件内部,我编写了代码,该代码以excel/pdf格式为我提供了使用方法
的报告ExportToHttpResponse(ExportFormatType.Excel,Response,true,"Report Name")给了我例外,因此在此方法之后
或者当我写btn.enable = true时最终阻塞;或使用javascript而不执行.
异常是无法评估表达式,因为代码已优化或本机框架位于调用堆栈的顶部

即,我必须在生成报告时启用btn.
当此方法被执行ExportToHttpResponse()我得到报告
所以在这种方法之后,我必须启用btn控制
-----------我的代码-----------------------------------

when i click btn control disable btn using javascript then btn click event call.
inside btn click event i write code which gives me report in excel/pdf format for that i use method
ExportToHttpResponse(ExportFormatType.Excel, Response, true, "Report Name") which gives me exception so after this method
or finally block when i write btn.enable=true; or use javascript then not executed.
exception is Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

i.e. i have to enable btn when report is generated.
as this method get executed ExportToHttpResponse() i got report
so after this method i have to enable btn control
-----------my code-----------------------------------

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, " Report name");}

        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            ex = null;
        }
        finally
        {
                      btnExcel.Enabled = true;


ScriptManager.RegisterClientScriptBlock(Page,this.GetType(),"CallJSFunction","myEnablefunction()",true);

}
}


ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJSFunction", "myEnablefunction()", true);

}
}

推荐答案


这篇关于按钮禁用但不启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:02