【问题标题】:Button disable but not enable按钮禁用但未启用
【发布时间】:2012-06-13 15:53:12
【问题描述】:

当我单击 btn 控件时,使用 javascript 禁用 btn,然后 btn 单击事件调用。 在 btn 点击事件中,我编写代码,为我使用方法提供 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);
    }
}

【问题讨论】:

  • 请包含javascriptmyEnablefunction()的内容。
  • function myEnablefunction(){ btnExcel.disabled=false;}

标签: asp.net


【解决方案1】:

如果你直接写到Response,所有的asp.net结构都被破坏了,所以你不能改变控件的属性,因为你已经干扰了asp.net的“自然”渲染。如果在导出过程中出现错误,则页面已损坏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多