按钮启用问题 [英] button enable problem

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

问题描述

我已使用javascript禁用了按钮
我有此代码,

 受保护的  void  btnExcel_Click(对象发​​件人,EventArgs e)
    {
        查看报告();
      
        尝试
        {
            Rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat,响应, true " 员工报告" );


        }
        捕获(例外)
        {
            Console.WriteLine(ex.Message);
            例如= ;
        }
        最终
        {
         btnExcel.enabled =  true ;
            Rpt.Dispose();
            Rpt.Close();
        }
       
    
    } 



在try块中出现异常,
无法优化表达式,因为代码已优化或本机框架位于调用堆栈的顶部

所以btnExcel.enabled = true;
该语句不会在finally块中执行

解决方案

在您的Funciton Rpt.ExportToHttpResponse()中可能是例外

对此方法发表评论,并检查应用程序是否正在运行并且是否启用了按钮?

我建议您检查一下功能.

如果删除try catch块并运行应用程序,则将获得错误所在的实际位置.


在try块中出现了异常,
您在方法ExportToHttpResponse中遇到异常.根据您在做什么,我可以猜出代码,并且我相信您正在其中执行Response.End.在VS中进行调试将告诉您确切的代码.

代替Response.End,您必须使用HttpContext.Current.ApplicationInstance.CompleteRequest方法将代码执行绕过到Application_EndRequest事件.

在此处查看详细信息: Microsoft支持:如果您使用Response.End,Response.Redirect或Server.Transfer,则会发生ThreadAbortException [ ^ ]

i have disable the button using javascript
i have this code ,

protected void btnExcel_Click(object sender, EventArgs e)
    {      
        view_report();
      
        try
        {
            Rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Employee Report");


        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            ex = null;
        }
        finally
        {
         btnExcel.enabled=true;
            Rpt.Dispose();
            Rpt.Close();
        }
       
    
    }



in try block got the exception ,
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

so btnExcel.enabled=true;
this statement not executed in finally block

解决方案

Might be exception in your Funciton Rpt.ExportToHttpResponse()

comment this method and check is application running and button is enabled or not?

i suggest you to check your Function.

if you remove try catch block and run application then you will get actual location where the error is.


in try block got the exception ,
You are getting an exception in your method ExportToHttpResponse. Based on what are you doing, I can guess the code and I believe you are doing a Response.End in it. Debugging in VS will tell you the exact line.

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest method to bypass the code execution to the Application_EndRequest event.

Look here for details: Microsoft Support: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer[^]


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆