共用方式為


Sys.WebForms.EndRequestEventArgs Class

Used by the endRequest event of the Sys.WebForms.PageRequestManager class to pass argument information to event handlers. The endRequest event is raised just after the postback request has finished processing.

Namespace: Sys.WebForms

Inherits: Sys.EventArgs

var args = new Sys.WebForms.EndRequestEventArgs(error, dataItems, response);

Constructors

Name

Description

Sys.WebForms.EndRequestEventArgs Constructor

Initializes a new instance of the EndRequestEventArgs class.

Members

Member name

Description

Sys.WebForms.EndRequestEventArgs dataItems Property

Gets a JSON data structure that contains data items that were registered by using the RegisterDataItem method of the ScriptManager class.

Sys.WebForms.EndRequestEventArgs error Property

Gets the Error object.

Sys.WebForms.EndRequestEventArgs errorHandled Property

Get or sets a value that indicates whether the error has been handled.

Sys.WebForms.EndRequestEventArgs response Property

Gets a response object that is represented by the WebRequestExecutor class.

Note

This class contains private members that support the client-script infrastructure and are not intended to be used directly from your code. Names of private members begin with an underscore ( _ ).

Remarks

An EndRequestEventArgs object is returned as a parameter in an event handler. You can use its error property to determine whether an error occurred and to obtain details about the error. You can also use the errorHandled property to determine whether the error has already been handled and to indicate that you have handled the error.

Example

The following example shows how to use two properties of the EndRequestEventArgs class. A Click event handler for a button in an UpdatePanel control throws an ArgumentException exception to simulate an unhandled exception. In the client script, a handler for the endRequest event of the PageRequestManager class checks the error property value. If the error is an unhandled server exception, the script sets the errorHandled property to true and displays an error message.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "https://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="https://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" 
  "https://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="https://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>

See Also

Reference

Sys.WebForms.PageRequestManager endRequest Event

Sys.WebForms.PageRequestManager Class