•参数类型:EndRequestEventArgs
–dataItems属性:获得服务器端注册的数据项
–error属性:获得异步刷新时获得的错误
–errorHandled属性:表明错误是否已被处理了
–response属性:获得这次请求获得的结果对象
•常用操作:
–处理异步刷新结果(异常、超时、取消, etc.)
–获得请求结果中额外的信息
–(能够)获得服务器端注册的数据项
处理异步刷新结果
aspx
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="5_HandleResponse.aspx.cs" Inherits="_5_HandleResponse" Title="HandleResponse" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%= DateTime.Now %><br />
<asp:Button ID="btnError" runat="server" Text="Error" OnClick="btnError_Click" />
<asp:Button ID="btnTimeout" runat="server" Text="Timeout" OnClick="btnTimeout_Click" />
<input type="button" value="Abort" onclick="Sys.WebForms.PageRequestManager.getInstance().abortPostBack();" />
<asp:Button ID="btnDataItem" runat="server" Text="Register DataItem" OnClick="btnDataItem_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<script language="javascript" type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
function(sender, e)
{
if (e.get_error())
{
e.set_errorHandled(true);
if (e.get_response().get_timedOut())
{
showMessage("您的请求已超时。");
}
else if (e.get_response().get_statusCode() != 200)
{
showMessage("遇到未知错误。");
}
else
{
showMessage(e.get_error().message);
}
}
else if (e.get_response().get_aborted())
{
showMessage("您的请求已被取消。");
}
else
{
var upId = "<%= this.UpdatePanel1.ClientID %>";
var item = e.get_dataItems()[upId];
showMessage("您注册了:" + item);
}
});
</script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%= DateTime.Now %><br />
<asp:Button ID="btnError" runat="server" Text="Error" OnClick="btnError_Click" />
<asp:Button ID="btnTimeout" runat="server" Text="Timeout" OnClick="btnTimeout_Click" />
<input type="button" value="Abort" onclick="Sys.WebForms.PageRequestManager.getInstance().abortPostBack();" />
<asp:Button ID="btnDataItem" runat="server" Text="Register DataItem" OnClick="btnDataItem_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<script language="javascript" type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
function(sender, e)
{
if (e.get_error())
{
e.set_errorHandled(true);
if (e.get_response().get_timedOut())
{
showMessage("您的请求已超时。");
}
else if (e.get_response().get_statusCode() != 200)
{
showMessage("遇到未知错误。");
}
else
{
showMessage(e.get_error().message);
}
}
else if (e.get_response().get_aborted())
{
showMessage("您的请求已被取消。");
}
else
{
var upId = "<%= this.UpdatePanel1.ClientID %>";
var item = e.get_dataItems()[upId];
showMessage("您注册了:" + item);
}
});
</script>
</asp:Content>
cs
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).AsyncPostBackTimeout = 3;
}
protected void btnError_Click(object sender, EventArgs e)
{
int two = 2;
int i = 3 / (two - 2);
}
protected void btnTimeout_Click(object sender, EventArgs e)
{
Thread.Sleep(5000);
}
protected void btnDataItem_Click(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).RegisterDataItem(this.UpdatePanel1, DateTime.Now.ToString());
}
{
ScriptManager.GetCurrent(this).AsyncPostBackTimeout = 3;
}
protected void btnError_Click(object sender, EventArgs e)
{
int two = 2;
int i = 3 / (two - 2);
}
protected void btnTimeout_Click(object sender, EventArgs e)
{
Thread.Sleep(5000);
}
protected void btnDataItem_Click(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).RegisterDataItem(this.UpdatePanel1, DateTime.Now.ToString());
}