使用asp.net ajax 得到一个服务端产生的异常信息

ContractedBlock.gif ExpandedBlockStart.gif GetExceptionInfo.aspx
 1ExpandedBlockStart.gifContractedBlock.gif<%@ 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>
 8ExpandedBlockStart.gifContractedBlock.gif    <script type="text/javascript">
 9    
10ExpandedSubBlockStart.gifContractedSubBlock.gif      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" />
19ExpandedBlockStart.gifContractedBlock.gif        <script type="text/javascript" language="javascript">
20        
21          var prm = Sys.WebForms.PageRequestManager.getInstance();
22          prm.add_endRequest(onEndRequest);
23
24ExpandedSubBlockStart.gifContractedSubBlock.gif          function onEndRequest(sender, args) {
25            var error = args.get_error();
26ExpandedSubBlockStart.gifContractedSubBlock.gif            if (error) {
27              var messageString = error.message;
28              messagePanel.innerHTML = getExceptionInfo(error.message);
29              args.set_errorHandled(true);
30            }

31          }

32          
33ExpandedSubBlockStart.gifContractedSubBlock.gif          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

 

 

ContractedBlock.gif ExpandedBlockStart.gif 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
 9ExpandedBlockStart.gifContractedBlock.gif{
10    protected void Page_Load(object sender, EventArgs e)
11ExpandedSubBlockStart.gifContractedSubBlock.gif    {
12
13    }

14    protected void Button1_Click(object sender, EventArgs e)
15ExpandedSubBlockStart.gifContractedSubBlock.gif    {
16      throw new Exception("抛出一个异常");
17    }

18}

19

转载于:https://www.cnblogs.com/aminic/archive/2008/10/06/1305041.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值