What is the difference between AsyncPostBackTrigger & PostBackTrigger?

48,055

Solution 1

Controls inside an UpdatePanel by default cause a partial page update, controls outside cause a postback, using these triggers it is possible to change this behaviour as required.

From http://seminaarit.codezone.fi/video/devdays-2007/track1/2/2-ASP-dotNET_AJAX_Extensions.ppt: (dead link)

AsyncPostBackTrigger

  • Converts postbacks into async callbacks * Typically used to trigger updates when controls outside an UpdatePanel post back * If ChildrenAsTriggers="false", can be used to specify which controls inside UpdatePanel should call back rather than post back

PostBackTrigger

  • Lets controls inside UpdatePanel post back. * Typically used to allow certain controls to post back when ChildrenAsTriggers="true"

Solution 2

Here's a blog post which explains the difference:

In the 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.

Solution 3

1. AsyncPostBackTrigger

it is the one which enforces Asynchonous post back of the Page.., i.e. the AJAX way. The data will be transacted without full post back. When you are using functionalities like login, you may use this.

Ex. You are having two dropDowns Viz., Countries and States. the states should be loaded when a country is selected and it should be changed on Countries change.

You may use AsyncPostBackTrigger in this scenario, which will populate the states ddl without full post back.

2. PostBackTrigger

It is the one which does not follow the AJAX functionalities, but the full post back as usually(as without using UpdatePanel). Situtions are there where you would not like to enforce Partial Post back (as explained in Point 1. above).

Like you are having FileUpload Control withing the UpdatePanel and when you do it by AsyncPostBack, you will not get any values to the server. It requires Full PostBack. in such a case you should use this trigger.

Solution 4

Suppose Button1 is inside your Update panel and Button2 is outside the update panel. Now let's undertsand that the controls that are outside the update panel are doing a Asyncpostback and that are inside creates a Syncpostback.

So as both buttons are on a form Button1 in inside Update panel and bUtton2 is outside it. So by the way by giving the Button2's ID and its Event name to the Asyncpostback Trigger as given in the example we suppose that now it will create a syncpostback with the updatepanel as like the Button1.

Share:
48,055

Related videos on Youtube

vmahdavi
Author by

vmahdavi

Updated on July 09, 2022

Comments

  • vmahdavi
    vmahdavi almost 2 years

    What is the difference between AsyncPostBackTrigger & PostBackTrigger?

  • ankit paul
    ankit paul over 11 years
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button2" EventName="Button2_Click" /> <asp:PostBackTrigger ControlID=""Button1" /> </Triggers> </asp:UpdatePanel>