GetExceptionInfo.aspx
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetExceptionInfo.aspx.cs" Inherits="GetExceptionInfo" %>
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml">
6<head runat="server">
7 <title></title>
8 <script type="text/javascript">
9
10 function pageLoad() {
11 }
12
13 </script>
14</head>
15<body>
16 <form id="form1" runat="server">
17 <div>
18 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
19 <script type="text/javascript" language="javascript">
20
21 var prm = Sys.WebForms.PageRequestManager.getInstance();
22 prm.add_endRequest(onEndRequest);
23
24 function onEndRequest(sender, args) {
25 var error = args.get_error();
26 if (error) {
27 var messageString = error.message;
28 messagePanel.innerHTML = getExceptionInfo(error.message);
29 args.set_errorHandled(true);
30 }
31 }
32
33 function getExceptionInfo(exceptionMessage) {
34 return exceptionMessage.substring(exceptionMessage.indexOf(':') + 1, exceptionMessage.length);
35 }
36
37 </script>
38 <asp:UpdatePanel runat="server" ID="UpdatePanel1">
39 <ContentTemplate>
40 <asp:Button runat="server" ID="Button1" Text="GetExceptionInfo"
41 onclick="Button1_Click" />
42 <div id="messagePanel">
43 </div>
44 </ContentTemplate>
45 </asp:UpdatePanel>
46 </div>
47 </form>
48</body>
49</html>
50
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetExceptionInfo.aspx.cs" Inherits="GetExceptionInfo" %>
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml">
6<head runat="server">
7 <title></title>
8 <script type="text/javascript">
9
10 function pageLoad() {
11 }
12
13 </script>
14</head>
15<body>
16 <form id="form1" runat="server">
17 <div>
18 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
19 <script type="text/javascript" language="javascript">
20
21 var prm = Sys.WebForms.PageRequestManager.getInstance();
22 prm.add_endRequest(onEndRequest);
23
24 function onEndRequest(sender, args) {
25 var error = args.get_error();
26 if (error) {
27 var messageString = error.message;
28 messagePanel.innerHTML = getExceptionInfo(error.message);
29 args.set_errorHandled(true);
30 }
31 }
32
33 function getExceptionInfo(exceptionMessage) {
34 return exceptionMessage.substring(exceptionMessage.indexOf(':') + 1, exceptionMessage.length);
35 }
36
37 </script>
38 <asp:UpdatePanel runat="server" ID="UpdatePanel1">
39 <ContentTemplate>
40 <asp:Button runat="server" ID="Button1" Text="GetExceptionInfo"
41 onclick="Button1_Click" />
42 <div id="messagePanel">
43 </div>
44 </ContentTemplate>
45 </asp:UpdatePanel>
46 </div>
47 </form>
48</body>
49</html>
50
GetExceptionInfo.aspx.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.UI;
6using System.Web.UI.WebControls;
7
8public partial class GetExceptionInfo : System.Web.UI.Page
9{
10 protected void Page_Load(object sender, EventArgs e)
11 {
12
13 }
14 protected void Button1_Click(object sender, EventArgs e)
15 {
16 throw new Exception("抛出一个异常");
17 }
18}
19
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.UI;
6using System.Web.UI.WebControls;
7
8public partial class GetExceptionInfo : System.Web.UI.Page
9{
10 protected void Page_Load(object sender, EventArgs e)
11 {
12
13 }
14 protected void Button1_Click(object sender, EventArgs e)
15 {
16 throw new Exception("抛出一个异常");
17 }
18}
19