会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
aminic
我是一个程序员?
博客园
首页
新随笔
联系
订阅
管理
使用asp.net ajax 得到一个服务端产生的异常信息
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
GetExceptionInfo.aspx.cs
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Linq;
4
using
System.Web;
5
using
System.Web.UI;
6
using
System.Web.UI.WebControls;
7
8
public
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
posted @
2008-10-06 21:18
aminic
阅读(
115
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告