Sys.WebForms.EndRequestEventArgs 类
更新:2007 年 11 月
由 Sys.WebForms.PageRequestManager 类的 endRequest 事件用来将参数信息传递给事件处理程序。在回发请求完成处理后即引发 endRequest 事件。
命名空间:Sys.WebForms
new Sys.WebForms.EndRequestEventArgs();
构造函数
名称 |
说明 |
---|---|
初始化 EndRequestEventArgs 类的新实例。 |
成员
成员名称 |
说明 |
---|---|
获取一个 JSON 数据结构,该数据结构包含使用 ScriptManager 类的 RegisterDataItem 方法注册的数据项。 |
|
获取 Error 对象。 |
|
获取或设置一个值,该值指示是否已处理错误。 |
|
获取由 WebRequestExecutor 类表示的响应对象。 |
说明: |
---|
此类包含支持客户端-脚本基础结构的私有成员,不能在代码中直接使用。私有成员的名称必须以下划线开头 ( _ )。 |
备注
EndRequestEventArgs 对象作为事件处理程序中的参数返回。可以使用它的 error 属性确定是否发生了错误并获取有关错误的详细信息。还可以使用 errorHandled 属性确定是否已对错误进行处理,并在处理错误后指示已对错误进行处理。
示例
下面的示例演示如何使用 EndRequestEventArgs 类的两个属性。UpdatePanel 控件中按钮的 Click 事件处理程序引发 ArgumentException 异常来模拟未处理的异常。在客户端脚本中,PageRequestManager 类的 endRequest 事件的处理程序检查 error 属性值。如果该错误是未处理的服务器异常,该脚本会将 errorHandled 属性设置为 true 并显示错误消息。
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub ErrorProcessClick_Handler(ByVal sender As Object, ByVal e As System.EventArgs)
' This handler demonstrates an error condition. In this example
' the server error gets intercepted on the client and an alert is shown.
Throw New ArgumentException()
End Sub
Protected Sub SuccessProcessClick_Handler(ByVal sender As Object, ByVal e As System.EventArgs)
'This handler demonstrates no server side exception.
UpdatePanelMessage.Text = "The asynchronous postback completed successfully."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>PageRequestManager endRequestEventArgs Example</title>
<style type="text/css">
body {
font-family: Tahoma;
}
div.AlertStyle{
position: absolute; width: 90%; top: 0%;
visibility: hidden; z-index: 99; background-color: #ffff99;
font-size: larger; font-family: Tahoma;
border-right: navy thin solid; border-top: navy thin solid;
border-left: navy thin solid; border-bottom: navy thin solid;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
var divElem = 'AlertDiv';
var messageElem = 'UpdatePanelMessage';
function ToggleAlertDiv(visString)
{
var adiv = $get(divElem);
adiv.style.visibility = visString;
}
function ClearErrorState() {
$get(messageElem).innerHTML = '';
ToggleAlertDiv('hidden');
}
function EndRequestHandler(sender, args)
{
if (args.get_error() != null)
{
var errorName = args.get_error().name;
if (errorName.length > 0 )
{
args.set_errorHandled(true);
ToggleAlertDiv('visible');
$get(messageElem).innerHTML = 'The panel did not update successfully.';
}
}
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="Server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
<asp:Label ID="UpdatePanelMessage" runat="server" />
<br />
Last update:
<%= DateTime.Now.ToString() %>
.
<br />
<asp:Button runat="server" ID="Button1" Text="Submit Successful Async Postback"
OnClick="SuccessProcessClick_Handler" OnClientClick="ClearErrorState()" />
<asp:Button runat="server" ID="Button2" Text="Submit Async Postback With Error"
OnClick="ErrorProcessClick_Handler" OnClientClick="ClearErrorState()" />
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div id="AlertDiv" class="AlertStyle" style="">
<div id="AlertMessage" style="float: left">
There was a problem processing the last request.
</div>
<div id="AlertLinks" style="float: right">
<a title="Hide this alert." href="#" onclick="ClearErrorState()">
close</a> | <a title="Send an email notifying the Web site owner."
href="mailto:someone@example.com" onclick="ToggleAlertDiv('hidden', 'AlertDiv')">
notify</a></div>
</div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void ErrorProcessClick_Handler(object sender, EventArgs e)
{
// This handler demonstrates an error condition. In this example
// the server error gets intercepted on the client and an alert is shown.
throw new ArgumentException();
}
protected void SuccessProcessClick_Handler(object sender, EventArgs e)
{
// This handler demonstrates no server side exception.
UpdatePanelMessage.Text = "The asynchronous postback completed successfully.";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>PageRequestManager endRequestEventArgs Example</title>
<style type="text/css">
body {
font-family: Tahoma;
}
div.AlertStyle{
position: absolute; width: 90%; top: 0%;
visibility: hidden; z-index: 99; background-color: #ffff99;
font-size: larger; font-family: Tahoma;
border-right: navy thin solid; border-top: navy thin solid;
border-left: navy thin solid; border-bottom: navy thin solid;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
var divElem = 'AlertDiv';
var messageElem = 'UpdatePanelMessage';
function ToggleAlertDiv(visString)
{
var adiv = $get(divElem);
adiv.style.visibility = visString;
}
function ClearErrorState() {
$get(messageElem).innerHTML = '';
ToggleAlertDiv('hidden');
}
function EndRequestHandler(sender, args)
{
if (args.get_error() != null)
{
var errorName = args.get_error().name;
if (errorName.length > 0 )
{
args.set_errorHandled(true);
ToggleAlertDiv('visible');
$get(messageElem).innerHTML = 'The panel did not update successfully.';
}
}
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="Server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
<asp:Label ID="UpdatePanelMessage" runat="server" />
<br />
Last update:
<%= DateTime.Now.ToString() %>
.
<br />
<asp:Button runat="server" ID="Button1" Text="Submit Successful Async Postback"
OnClick="SuccessProcessClick_Handler" OnClientClick="ClearErrorState()" />
<asp:Button runat="server" ID="Button2" Text="Submit Async Postback With Error"
OnClick="ErrorProcessClick_Handler" OnClientClick="ClearErrorState()" />
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div id="AlertDiv" class="AlertStyle" style="">
<div id="AlertMessage" style="float: left">
There was a problem processing the last request.
</div>
<div id="AlertLinks" style="float: right">
<a title="Hide this alert." href="#" onclick="ClearErrorState()">
close</a> | <a title="Send an email notifying the Web site owner."
href="mailto:someone@example.com" onclick="ToggleAlertDiv('hidden', 'AlertDiv')">
notify</a></div>
</div>
</div>
</form>
</body>
</html>