【发布时间】:2011-10-20 22:50:14
【问题描述】:
这东西快把我逼疯了。我试图在部分回发期间拦截异常服务器端,设置错误消息以在 javascript 警报中显示在客户端上。
但我只是在 Firefox 控制台上收到以下错误:
uncaught exception: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Tentativo di divisione per zero.' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "JS frame :: resource://firebug_rjs/net/spy.js :: callPageHandler :: line 796" data: no]
根本没有警报。
我在涉及 Telerik 组件的复杂项目中遇到了这个问题,但我已将问题简化为基本问题,following this simple example,问题仍然存在。
案例:
Default.aspx
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptManager" runat="server" OnAsyncPostBackError="scriptManager_OnAsyncPostBackError"></asp:ScriptManager>
<div>
<asp:UpdatePanel ID="upd" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_OnClick" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
Default.aspx.cs
protected void scriptManager_OnAsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
scriptManager.AsyncPostBackErrorMessage = e.Exception.Message;
}
protected void btnSend_OnClick(object sender, EventArgs e)
{
// this will throw and Exception
int aa = Convert.ToInt32(TextBox1.Text) / Convert.ToInt32(TextBox2.Text);
}
我在 Firefox 和 Internet Explorer 中尝试过 VS2010/.NET 4.0 和 VS2008/.NET 3.5,问题是一样的。
请问,有人有什么想法吗?
【问题讨论】:
标签: asp.net ajax exception-handling updatepanel scriptmanager