简体   繁体   English

ScriptManager1.AsyncPostBackErrorMessage未显示错误消息

[英]ScriptManager1.AsyncPostBackErrorMessage not showing error message

I've always used the following two bits of code (which use to work) to catch Ajax asyncPostBackError s. 我总是使用以下两位代码(用于工作)来捕获Ajax asyncPostBackError

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

and

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

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: 但是现在即使已经在此事件处理函数中捕获到未处理的异常并且使用Exception消息设置了AsyncPostBackErrorMessage ,无论异常消息是什么,我总是在警告框中的页面中获得相同的错误报告, :

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() ....

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. 如果您有一个未处理的asyncPostBack异常并且没有连接Scriptmanger's asyncPostBackError事件处理程序方法,则会出现同样的错误。

No matter what I do I get the same error. 无论我做什么,我都会得到同样的错误。 What would be causing this? 会导致什么?

This may be a shot in the dark, but maybe global exception handling is taking place after your ScriptManager1_AsyncPostBackError function is called. 这可能是一个黑暗的镜头,但可能在调用ScriptManager1_AsyncPostBackError函数后进行全局异常处理。 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. 如果该异常处理正在执行server.transfer到错误页面,则脚本管理器将无法解析发回的HTML。

This was happening on one of my sites and was solved by adding Server.ClearError() to the ScriptManager1_AsyncPostBackError function. 这发生在我的一个站点上,并通过将Script.ClearError()添加到ScriptManager1_AsyncPostBackError函数来解决。 This prevented Global.Application_Error function from being called. 这阻止了Global.Application_Error函数。

It seems i'm facing the same problem after upgrading from VS 2005 to VS 2008. I use this code: 从VS 2005升级到VS 2008后,我似乎面临着同样的问题。我使用这段代码:

if (e.Exception is LandingPageUIExceptionInvalidMSISDN)
{
    msgresolved = "ErrorPopUpInvalidNumber";
    ScriptManager.GetCurrent(Page).AsyncPostBackErrorMessage = msgresolved;
}

in order to handle the exception and display a proper error message. 为了处理异常并显示正确的错误消息。 The AsyncPostBackErrorMessage is assigned properly but at client side when the following is executed in JavaScript: AsyncPostBackErrorMessage已正确分配,但在客户端,在JavaScript中执行以下操作时:

var ErrorPopUpDivID = e.get_error().message;
alert(ErrorPopUpDivID);

The ErrorPopUpDivID is not what i had asigned to AsyncPostBackErrorMessage . ErrorPopUpDivID不是我所谓的AsyncPostBackErrorMessage It used to work for me too. 它曾经也适合我。 I'll try to figure out if it might be a .NET 3.5 issue. 我将试着弄清楚它是否可能是.NET 3.5的问题。

Finally the following 3 lines of JavaScript solved my problem: 最后,以下3行JavaScript解决了我的问题:

var ErrorPopUpDivID = e.get_error().message;
var re = new RegExp("Sys.*: ", "g");
ErrorPopUpDivID = ErrorPopUpDivID.replace(re, "");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM