Sys.WebForms.PageRequestManager Class

Manages partial-page updates of server UpdatePanel controls in the browser. In addition, defines properties, events, and methods that can be used to customize a Web page by using client script.

Namespace: Sys.WebForms

Inherits: None

var prm = Sys.WebForms.PageRequestManager.getInstance();

Constructor

You do not create a new instance of the PageRequestManager class directly. Instead, an instance is available when partial-page rendering is enabled. Call the getInstance method to get the instance of the PageRequestManager class.

Members

Name

Description

Sys.WebForms.PageRequestManager Constructor

Initializes a new instance of the Sys.WebForms.PageRequestManager Class.

Sys.WebForms.PageRequestManager beginRequest Event

Raised before processing of an asynchronous postback starts and the postback request is sent to the server.

Sys.WebForms.PageRequestManager endRequest Event

Raised after an asynchronous postback is finished and control has been returned to the browser.

Sys.WebForms.PageRequestManager initializeRequest Event

Raised during the initialization of the asynchronous postback.

Sys.WebForms.PageRequestManager pageLoaded Event

Raised after all content on the page is refreshed as the result of either a synchronous or an asynchronous postback.

Sys.WebForms.PageRequestManager pageLoading Event

Raised after the response from the server to an asynchronous postback is received but before any content on the page is updated.

Sys.WebForms.PageRequestManager abortPostBack Method

Stops all updates that would occur as a result of an asynchronous postback.

Sys.WebForms.PageRequestManager dispose Method

Releases ECMAScript (JavaScript) resources and detaches events.

Sys.WebForms.PageRequestManager getInstance Method

Returns the instance of the PageRequestManager class for the page.

Sys.WebForms.PageRequestManager isInAsyncPostBack Property

Returns a value that indicates whether the PageRequestManager object is processing a postback.

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

The PageRequestManager class manages partial-page rendering in the browser. You can update regions on the page by using one or more UpdatePanel controls and a ScriptManager control.

You do not create an instance of the PageRequestManager directly. When partial-page rendering is enabled, an instance of the PageRequestManager class is automatically available. You can access it through the getInstance method.

The PageRequestManager class defines events that you can use to customize your page's partial-page rendering. The client infrastructure supports automatic event binding similar to the way that server page events are automatically bound to methods such as Page_Load. The following table lists client events that you can use, and scenarios in which you might handle them. The events are listed in the table in the order in which they are called by the PageRequestManager class.

PageRequestManager event

Description

initializeRequest

Raised before processing of the asynchronous request starts. You can use this event to cancel a postback.

beginRequest

Raised before processing of an asynchronous postback starts and the postback is sent to the server. You can use this event to set request headers or to begin an animation that indicates that the page is processing.

pageLoading

Raised after the response from the server to an asynchronous postback is received but before any content on the page is updated. You can use this event to provide a custom transition effect for updated content.

pageLoaded

Raised after all content on the page is refreshed, as a result of either a synchronous or an asynchronous postback. You can use this event to provide a custom transition effect for updated content.

endRequest

Raised after an asynchronous postback is finished and control has been returned to the browser. You can use this event to provide a notification to users or to log errors.

If the page contains at least one UpdatePanel control and the ScriptManager control's SupportsPartialRendering value is true (the default value), the JavaScript library that defines the PageRequestManager class is registered with the ScriptManager control and is available to the page.

Example

The following example shows how to use the beginRequest event to display a progress notification during asynchronous postbacks. The getInstance method is called to get the current PageRequestManager instance. Script is included in handlers for the beginRequest and endRequest events.

<%@ 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 ProcessClick_Handler(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(2000);
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>PageRequestManager beginRequest Example</title>
    <style type="text/css">
    body {
        font-family: Tahoma;
    }
    div.AlertStyle
    {
      background-color: #FFC080;
      top: 95%;
      left: 1%;
      height: 20px;
      width: 270px;
      position: absolute;
      visibility: hidden;
    }
    </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_beginRequest(BeginRequestHandler);
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function BeginRequestHandler(sender, args)
                {
                     var elem = args.get_postBackElement();
                     ActivateAlertDiv('visible', 'AlertDiv', elem.value + ' processing...');
                }
                function EndRequestHandler(sender, args)
                {
                     ActivateAlertDiv('hidden', 'AlertDiv', '');
                }
                function ActivateAlertDiv(visstring, elem, msg)
                {
                     var adiv = $get(elem);
                     adiv.style.visibility = visstring;
                     adiv.innerHTML = msg;                     
                }
            </script>

            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="Server">
                <ContentTemplate>
                    <asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
                        Last update:
                        <%= DateTime.Now.ToString()%>.
                        <br />
                        <asp:Button runat="server" ID="Button1" Text="Process 1" OnClick="ProcessClick_Handler" />
                        <asp:Button runat="server" ID="Button2" Text="Process 2" OnClick="ProcessClick_Handler" />
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>
            <div id="AlertDiv" class="AlertStyle">
            </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 ProcessClick_Handler(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(2000);
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>PageRequestManager beginRequest Example</title>
    <style type="text/css">
    body {
        font-family: Tahoma;
    }
    div.AlertStyle
    {
      background-color: #FFC080;
      top: 95%;
      left: 1%;
      height: 20px;
      width: 270px;
      position: absolute;
      visibility: hidden;
    }
    </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_beginRequest(BeginRequestHandler);
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function BeginRequestHandler(sender, args)
                {
                     var elem = args.get_postBackElement();
                     ActivateAlertDiv('visible', 'AlertDiv', elem.value + ' processing...');
                }
                function EndRequestHandler(sender, args)
                {
                     ActivateAlertDiv('hidden', 'AlertDiv', '');
                }
                function ActivateAlertDiv(visstring, elem, msg)
                {
                     var adiv = $get(elem);
                     adiv.style.visibility = visstring;
                     adiv.innerHTML = msg;                     
                }
            </script>

            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="Server">
                <ContentTemplate>
                    <asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
                        Last update:
                        <%= DateTime.Now.ToString()%>.
                        <br />
                        <asp:Button runat="server" ID="Button1" Text="Process 1" OnClick="ProcessClick_Handler" />
                        <asp:Button runat="server" ID="Button2" Text="Process 2" OnClick="ProcessClick_Handler" />
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>
            <div id="AlertDiv" class="AlertStyle">
            </div>
        </div>
    </form>
</body>
</html>

See Also

Reference

ScriptManager

UpdatePanel