Timer in asp.net works when I run the application in localhost and when I upload and check online timer just don't work.
I have a condition when user click on "Request Item" button, in a label a message should show as "Submitted successfully" else "Some Error Message". So, What I did was, I created an update panel and inside that I placed a submit button with 2 labels one for successful message and another for error message. And a timer control, which I've setted up for 2 seconds in order to show message for just 2 seconds and hide them.
Here is my sorce code:
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Request Item" Width="128px" OnClick="btnAdd_Click1" Height="38px" />
<asp:Label ID="lblSuccess" runat="server" Font-Bold="True" ForeColor="#00CC00"></asp:Label>
<asp:Label ID="lblErrorMessage" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
<br />
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick1" Enabled="False">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
Below is the code where timer control is triggered under "Request Item" button.
lblSuccess.Visible = true;
lblSuccess.Text = "Records Successfully Saved!";
Timer1.Enabled = true;
Below is the code under timer tick event.
protected void Timer1_Tick1(object sender, EventArgs e)
{
txtCount.Text = txtCount.Text + 1;
if (txtCount.Text == "11") //Here "11" is counted as each timer tick. 1 for 1 timer tick
{
lblSuccess.Visible = false;
lblErrorMessage.Visible = false;
Timer1.Enabled = false;
txtCount.Text = "";
}
}