AsyncPostBackErrorMessage不显示错误消息

AsyncPostBackErrorMessage不显示错误消息

本文介绍了ScriptManager1.AsyncPostBackErrorMessage不显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用以下两段代码(用于工作)来捕获Ajax asyncPostBackError s.

I've always used the following two bits of code (which use to work) to catch Ajax asyncPostBackErrors.

<asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError" />

protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
ScriptManager1.AsyncPostBackErrorMessage = e.Exception.Message;
}

但是,即使此事件处理函数中捕获了未处理的异常,并且已使用Exception消息设置了 AsyncPostBackErrorMessage ,但在警报页面中,我始终会收到相同的错误报告框,无论异常消息是什么,都说:

But now even though the unhandled exception has been caught in this event handler function and the AsyncPostBackErrorMessage been set with the Exception message, I'm always getting the same error reporting in the page in a alert box no matter what the exception message was, saying:

Error: Sys.WebForms.PageRequestManagerParserErrorException: The message recieved from the server could not be parsed. Common causes for this error are when the response is modified by calls to the Respnse.Write() ....

该错误与如果遇到未处理的 asyncPostBack 异常并且未连接 Scriptmanger的 asyncPostBackError 时将发生的错误相同事件处理程序方法.

The error is the same error you would get if you had an unhandled asyncPostBack exception and you didn't wire up the Scriptmanger's asyncPostBackError event handler method.

无论我做什么我都会遇到相同的错误.是什么原因造成的?

No matter what I do I get the same error. What would be causing this?

推荐答案

这可能是黑暗中的一幕,但是在调用 ScriptManager1_AsyncPostBackError 函数之后,可能正在进行全局异常处理.如果该异常处理正在对错误页面进行 server.transfer ,则脚本管理器将无法解析回送的HTML.

This may be a shot in the dark, but maybe global exception handling is taking place after your ScriptManager1_AsyncPostBackError function is called. If that exception handling is doing a server.transfer to an error page, then the HTML sent back will not be parsable by the script manager.

这是在我的一个站点上发生的,并通过在 ScriptManager1_AsyncPostBackError 函数中添加Server.ClearError()来解决.这样可以防止调用 Global.Application_Error 函数.

This was happening on one of my sites and was solved by adding Server.ClearError() to the ScriptManager1_AsyncPostBackError function. This prevented Global.Application_Error function from being called.

这篇关于ScriptManager1.AsyncPostBackErrorMessage不显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:24