Total Pageviews
Thursday, June 25, 2009
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” />
<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();
}
}
Subscribe to:
Post Comments (Atom)
Blog Archive
Ideal SQL Query For Handling Error & Transcation in MS SQL
BEGIN TRY BEGIN TRAN --put queries here COMMIT; END TRY BEGIN CATCH IF @@TRANCOUNT>0 BEGIN SELECT @@ERROR,ERRO...
-
All we need to use the Custom paging in grid view without object data source. Here i am going to explain my code which is used in custom pa...
-
One of the common requests in ASP.NET is to submit a form when visitor hits an Enter key. That could be a case if, for example you want to m...
-
using System.Data; using System.Data.SqlClient; using System.Text; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; ...
its really very Nice.
ReplyDeletecan u explain more about ajax here