How to check Page is Asychrous Postback or not ? [Resolved]

Posted by Kasibabu under ASP.NET AJAX on 10/3/2011 | Points: 10 | Views : 1898 | Status : [Member] | Replies : 3
source code
-------------------------
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="20000" ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>

-----------------------------------code beind-----------------------
protected void Page_Load(object sender, EventArgs e)
{

if (ScriptManager1.IsInAsyncPostBack==true)
{
Label1.Text = "page is processing as ASynchrouns....";
}
else
{
Label1.Text = "page is processing as Synchronus";
}
}
why page_load code is executed 2 times for first request.
and next(every timer tick interval) onwords if(ScriptManager1.IsInAsyncPostBack==true) is executed succefully. but Label1.text shows Synchrous only..........
my remaining code is
protected void Timer1_Tick(object sender, EventArgs e)
{

if (ScriptManager1.IsInAsyncPostBack)
{
Label2.Text = DateTime.Now.ToString();

}
else
{
Label2.Text = "this is synchrous postback";
}
}

Regards,
Kasi babu



Responses

Posted by: Ndebata on: 10/3/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi
I could you are using two labels label1 and label2 and you are keeping only label2 inside the updatepanel, thats why other label is not updating on async postback, try to keep both inside the update panel you will see the change
<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="3000" ontick="Timer1_Tick"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>



Kasibabu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kasibabu on: 10/4/2011 [Member] Starter | Points: 25

Up
0
Down

hi Ndebata
this working fine.
but why for the first request(first time) page_load raised 2 times.


Regards,
Kasi babu

Kasibabu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/4/2011 [Member] Starter | Points: 25

Up
0
Down
I have checked, page_load is calling once for the first time.
Its a better approach to use the override method OnLoad instead of Page_Load.

Thanks,
Debata

Kasibabu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response