Passing Additional Information During an Asynchronous Postback : Asynchronous Event « Ajax « ASP.NET Tutorial






<%@ 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 dtlProduct_DataBound(object sender, EventArgs e)
    {
        string productTitle = (string)DataBinder.Eval(dtlProduct.DataItem, "Title");

        if (sm1.IsInAsyncPostBack)
        {
            sm1.RegisterDataItem(Head1, productTitle);
        }
        else
        {
            Head1.Title = productTitle;
            hTitle.InnerHtml = productTitle;
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel DataItem</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:ScriptManager
        id="sm1"
        Runat="server" />

    <h1 id="hTitle" runat="server"></h1>


    <asp:UpdatePanel
        id="upSearch"
        Runat="server">
        <ContentTemplate>

        <asp:DetailsView
            id="dtlProduct"
            DataSourceID="srcProducts"
            AllowPaging="true"
            Runat="server" OnDataBound="dtlProduct_DataBound" />

        </ContentTemplate>
    </asp:UpdatePanel>

    <asp:SqlDataSource
        id="srcProducts"
        ConnectionString='<%$ ConnectionStrings:con %>'
        SelectCommand="SELECT Id,Title,Director FROM Product"
        Runat="server" />

    </div>
    </form>
    <script type="text/javascript">

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

    function prm_pageLoaded(sender, args)
    {
        if (prm.get_isInAsyncPostBack())
        {
            var productTitle = args.get_dataItems()['Head1'];
            document.title = productTitle;
            $get('hTitle').innerHTML = productTitle;
        }
    }
    </script>
</body>
</html>








20.3.Asynchronous Event
20.3.1.Canceling the Current Asynchronous Postback
20.3.2.Aborting the Previous Asynchronous Postback
20.3.3.Passing Additional Information During an Asynchronous Postback