ErrorMessage.aspx
<style type="text/css">
#errormsg{
width:300px;
height:150px;
padding:10px;
border:solid 1px black;
background:#ffd;
text-align:left;
display:none;
position:absolute;
left:50px;
top:50px;
}
</style>
<script type="text/javascript">
function pageLoad(){
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);
}
function onEndRequest(sender,e){
if(e.get_error()){
$get("errormsg").style.display="block";
$get("lblMsg").innerText=e.get_error().description;
e.set_errorHandled(true);
}
}
function close1(){
$get("errormsg").style.display="none";
}
</script>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server" OnAsyncPostBackError="PostBackError">
</asp:ScriptManager>
<asp:Button ID="Button1" runat="server" Text="throw exception" OnClick="btn_click" />
<div id="errormsg">
<h3>Error Occurs</h3>
<p>
<span id="lblMsg"></span>
</p>
<p><input type="button" οnclick="close1()" value="close" />
</p>
</div>
</div>
</form>
ErrorMessage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Button1);
}
protected void btn_click(object sender, EventArgs e)
{
throw new Exception("trigger a error!");
}
protected void PostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
ScriptManager1.AsyncPostBackErrorMessage = e.Exception.Message;
}