Aspx < Form ID = " Form1 " Runat = " Server " >
< ASP: scriptmanager ID = " Scriptmanager1 " Runat = " Server " Allowcustomerrorsredirect = " False " Onasyncpostbackerror = " Scriptmanagerpolicasyncpostbackerror " >
</ ASP: scriptmanager >
< ASP: updatepanel ID = " Updatepanel1 " Runat = " Server " >
< Contenttemplate >
< ASP: button ID = " Button1 " Runat = " Server " Text = " Button " Onclick = " Button#click " />
</ Contenttemplate >
</ ASP: updatepanel >
< Div ID = " Error " > </ Div >
< Script Type = " Text/JavaScript " Language = " Javascript " >
SYS. webforms. pagerequestmanager. getinstance (). add_endrequest (function (sender, E)
{
E. set_errorhandled ( True );
$ Get ( " Error " ). Innerhtml = " Sorry, an error has occurred: " + E. get_error (). message;
SetTimeout (function () {$ Get ( " Error " ). Innerhtml = "" ;}, 3000 );
});
</ Script >
</ Form >
CSProtected VoidPage_load (ObjectSender, eventargs E)
{
}
Protected Void Button#click ( Object Sender, eventargs E)
{
Throw New Exception ( " Custom error! " );
}
Protected Void Scriptmanagerpolicasyncpostbackerror ( Object Sender, asyncpostbackerroreventargs E)
{
Scriptmanager. getcurrent ( This ). Asyncpostbackerrormessage = E. Exception. message;
}
After you click the button1 button < Div ID = " Error " > </ Div > Show sorry, an error has occurred: custom error !, Custom error is the custom error message in button#click. After three seconds, the error message automatically disappears. It is setTimeout (function () {$ Get ( " Error " ). Innerhtml = "" ;}, 3000 ); .