How AsyncPostBackTrigger and PostBackTrigger works in ASP.Net

Last Reply 9 months ago By dharmendr

Posted 9 months ago

how postback trigger and asynchronous postback trigger works in the code

When i clicked on click button,both time changed.ie. Page Generated @ 11:23:00 AM Internal @ 11:23:00 AM when i clicked on async button,one time changed ie. Asych click @ 11:25:45 AM what is exactly happening.. I am just confused with the Page load. in both the cases,postbacktrigger and asyncpostbacktrigger.Is it loading the whole page?

i am referring the below code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            Page Generated @ 
            <asp:Label runat="server" ID="uiPageTime" />
            <p />
            <asp:UpdatePanel runat="server" ID="update" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Label runat="server" ID="uiTime" />
                    <asp:Button runat="server" ID="uiInternalButton" Text="Click" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="uiAsynch" EventName="click" />
                    <asp:PostBackTrigger ControlID="uiInternalButton" />
                </Triggers>
            </asp:UpdatePanel>
            <asp:Button runat="server" ID="uiPostback" Text="Click" />
            <asp:Button runat="server" ID="uiAsynch" Text="Asynch" />
        </div>
    </form>
</body>
</html>

 

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Init(object sender, EventArgs e)
    {
        uiAsynch.Click += uiAsynch_Click; uiPostback.Click += uiPostback_Click;
        uiInternalButton.Click += uiInternalButton_Click;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        uiPageTime.Text = DateTime.Now.ToLongTimeString();
        if (!IsPostBack)
        {
            uiTime.Text = DateTime.Now.ToLongTimeString();
        }
    }

    private void uiInternalButton_Click(object sender, EventArgs e)//postbacktriger
    {
        uiTime.Text = "Internal @ " + DateTime.Now.ToLongTimeString();
    }
    private void uiPostback_Click(object sender, EventArgs e)
    {
        uiTime.Text = "Postback click @ " + DateTime.Now.ToLongTimeString();
        update.Update();
    }
    private void uiAsynch_Click(object sender, EventArgs e)//asynchronuspostbacktrigger
    {
        uiTime.Text = "Asych click @ " + DateTime.Now.ToLongTimeString();
        update.Update();
    }
}