i want to use timer in my pages..below is the code that i had used..
its working fine when i used it with a new page..but when i used it with my master page and run in browser it will only show the time..i had to refresh it every time to see the next time...plz help me with this....

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>
<br />
<asp:Label ID="Label1" runat="server" style="color: #FFFFFF" ></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID ="Timer1" EventName ="Tick" />
</Triggers>

</asp:UpdatePanel>
<br /><br />

<asp:Timer ID="Timer1" runat="server" Interval ="60" >
</asp:Timer>

............................................


code c#

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToString();
}


protected void Timer1_Tick1(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToString();
}

}

Here is your solution..

default.aspx

<asp:ScriptManager ID="ScriptManager1" runat="server" />      
<asp:Timer ID="Timer1" runat="server" Interval="50" OnTick="Timer1_Tick" />        
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>

default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToString("hh:mm:ss");
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToString("hh:mm:ss");
    }

Thanx..
nw its working fine......
Thanx alot....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.