AsyncPostBackTrigger vs PostBackTrigger
Posted by Ramani Sandeep on April 7, 2009
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" />
<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>
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();
update.Update();
}
private void uiAsynch_Click(object sender, EventArgs e)
{
uiTime.Text = "Asych click @ " + DateTime.Now.ToLongTimeString();
update.Update();
}
}
Advertisement
Gnosis said
very helpfull, thank you very much, i will use it on my site
Abhijit said
Good example …..
It is help to better understand the AsyncPostBackTrigger and PostBackTrigger..
Thanks…
Abhijit
Denny said
Very very useful. Thanks a lottttttttttttt
trr said
rtytr
Ramani Sandeep said
what is this rtytr means??
Hena said
Its really gud….
Padmanabha said
Its really very nice example…..
sandra said
BcnRVe
bishnu said
Good example …..
Yasmeen said
good example
krishna said
hello i want (“http://weblogs.asp.net/jstengel/archive/2008/04/25/flash-file-upload-server-control.aspx”) 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
krishna said
i want asp.net ajax file upload progress bar ….
plz help me…. for that
Ramani Sandeep said
What error you are facing..??
HKJHJKH said
HJKHJK