AsyncPostBackTrigger vs PostBackTrigger

In the <triggers> template in an update panel, there are the options of an AsyncPostBackTrigger or a PostBackTrigger.

By default, controls outside of an update panel will trigger a normal synchronous post back.  The AsyncPostBackTrigger “wires” up these controls to trigger an asynchronous post back.  Conversely, controls declared inside an update panel will trigger an asynchronous call by default.  The PostBackTrigger short circuits this, and forces the control to do a synchronous post back.

Utilizing a simple “time” example:

 <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
            Page Generated @
            <asp:Label runat="server" ID="uiPageTime" />
            <p />
            <asp:UpdatePanel runat="server" ID="update" UpdateMode="Conditional">
                    <asp:Label runat="server" ID="uiTime" />
                    <asp:Button runat="server" ID="uiInternalButton" Text="Click" />
                    <asp:AsyncPostBackTrigger ControlID="uiAsynch" EventName="click" />
                    <asp:PostBackTrigger ControlID="uiInternalButton" />
            <asp:Button runat="server" ID="uiPostback" Text="Click" />
            <asp:Button runat="server" ID="uiAsynch" Text="Asynch" />

And the code behind file.

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)
            uiTime.Text = "Internal @ " + DateTime.Now.ToLongTimeString();

        private void uiPostback_Click(object sender, EventArgs e)
            uiTime.Text = "Postback click @ " + DateTime.Now.ToLongTimeString();

        private void uiAsynch_Click(object sender, EventArgs e)
            uiTime.Text = "Asych click @ " + DateTime.Now.ToLongTimeString();

21 thoughts on “AsyncPostBackTrigger vs PostBackTrigger

  1. Good example …..
    It is help to better understand the AsyncPostBackTrigger and PostBackTrigger..


  2. hello i want (“”) this type of progress bar here provide dounload opetion , i was dounload this code n run but i m not enable to run this code some Dll error eccur plz solve it n return me

  3. I was able to implement your code example completely. However, when I applied the same principal to a piece of my own code, I couldn’t get it to work. Is there something special you have to do if the control you are using is a dropdownlist? I have the list inside the updatepanel so no trigger should be needed as it will be work like the internal button in your wexample. I do have an event handles on the selectedindex change of the dropdownlist, but it isn’t called.

  4. Yungang is very good to visit in combination with Wutai Mountain and Pinyao Ancient city.

    All these places are found in shanxi province China. We run tours to these places daily.

    They are all Unesco World Heritage and very special for world culture.

    Yungang’s grottoes are around a site that is a park and can be visited
    be all age groups.
    It is also suitable for children. The demonstration of Buddhist Art is exceptional and a true
    testament to the strength of this religion at that period in Chinese history.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s