Asp.net ajax exception handling details (1/2)

Source: Internet
Author: User

1. register the asyncpostbackerror event of scriptmanager, implement it on the server, and throw an exception that has been processed (based on whether the event is null, you may need to throw e. exception or e. exception. innerexception)

2. The client uses js to respond. sys. webforms. pagerequestmanager. getinstance (). add_endrequest (endrequesthandler); add a handler.

3. Implement endrequesthandler. The error message is basically in the second parameter "args,

4. This is done now. As no ready-made documents are found on the Internet (leave a message if any), what is going on in this args?

There are many contents. I 'd like to write out the enumeration method first.

Sys. webforms. pagerequestmanager. getinstance (). add_endrequest (endrequesthandler );

Function endrequesthandler (sender, args ){
// If (args. get_error ()! = Undefined) {alert (args. get_error (). message. replace (/. * exception:/, ''); args. set_errorhandled (true );}
If (args. get_error ()! = Undefined ){
Var members = 'args' members are: nn ';
For (var I in args ){
Members + = 'T' + I;
Var ai = eval ("args." + I );
If (typeof ai = "function "){
Try {
Members + = "()";
Ai = eval ("args." + I + "()");
} Catch (err ){
Members + = "not implement n ";
Continue;
}
}
Members + = 'n ';
If (typeof ai = "string") continue;
For (var t in ai ){
Members + = 'TT' + t;
If (typeof ai = "function ")
Var ait = eval ("args." + I + "()." + t );
Else
Var ait = eval ("args." + I + "." + t );
If (typeof ait = "function "){
Try {
Members + = "()";
Ait = eval ("args." + I + "." + t + "()");
} Catch (err ){
Members + = "not implement n ";
Continue;
}
}
Members + = "n ";
If (typeof ait = "string") continue;
For (var m in ait ){
Members + = 'ttt' + m + 'n ';
}
}
}
Document. write ("<textarea style = 'width: 1000px; height: 600px; '>" + members + "</textarea>"); // If members is displayed, process it by yourself
Args. set_errorhandled (true );
}
}

1 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.