Saturday, 22 September 2012

Timer In ASP.Net Using AJAX

With the help of AJAX we can postback an specific  part of a web part.
Normally when we click on a control which has capability to postback its load entire
page which time and data consuming both.You can save your time and data cost both
With Ajax

  • ScriptManager
  • UpdatePanel
  • Timer
  • Label
ASP Source code *.aspx

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
Server side code *.aspx.cs

public partial class _Default : System.Web.UI.Page
    static int i;
    protected void Timer1_Tick(object sender, EventArgs e)
        Label1.Text = i.ToString();