Perfil de 锦毛鼠何从何从->止于至善FotosBlogListas Herramientas Ayuda

Blog


13/05/2009

在.net 3.5 下面,IE7 中updatePanel 异步回发的时候throw的异常无法alert出来

在code-behind throw exception 

如果是ASP.NET 2.0throw是可自动弹出jsMsgBox,但到了ASP.NET3.5,用throw 是会在IE内报js错误的.

搜索到了这个错误:UpdatePanel alert not showing when server exception thrown  http://forums.asp.net/t/1382061.aspx

解决方案: 

说明了ajax for .net 3.5 ajax 1.0的区别。

  • In ASP.NET Ajax 1.0, the server-side exception object is serialized into JSON. The JSON is sent to the client, which displays the exception’s message property in an alert box.
  • In ASP.NET Ajax for .NET 3.5, the server-side exception is still serialized into JSON and the JSON is still sent to the client. However, instead of displaying the exception’s message property in an alert box – a presumptuous design decision, if you want my opinion – the client throws the exception, which gives you the opportunity to handle it on the client side as you please.
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args)
{
    if (args.get_error() != undefined) {
        $get('Button1').value = "This button has been disabled for your safety.";
        $get('Button1').disabled = true;
        args.set_errorHandled(true);
    }
}
来源:http://www.globalnerdy.com/2008/12/03/a-fix-for-the-error-in-hour-9-of-teach-yourself-aspnet-ajax-in-24-hours-client-side-error-handling-in-aspnet-ajax-in-net-35/