asp.net中的计时器可以在localhost上正常运行,但不能在线运行

asp.net中的计时器可以在localhost上正常运行,但不能在线运行

问题描述:

当我在localhost中运行应用程序并且上载并检查在线计时器时,asp.net中的计时器正常工作.

Timer in asp.net works when I run the application in localhost and when I upload and check online timer just don't work.

当用户单击请求项"按钮时,我有一个条件,标签中的消息应显示为已成功提交",否则显示为某些错误消息".因此,我要做的是,创建了一个更新面板,并在其中放置了一个带有2个标签的提交按钮,其中一个用于表示成功消息,另一个用于表示错误消息.还有一个计时器控件,我将其设置为2秒钟,以便仅显示2秒钟并隐藏消息.

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.

这是我的代码:

<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 = "";
        }
    }

如果您使用的是 ToolScriptManager ,请尝试在其中添加属性 CombineScript ="false" 并尝试.

if you are using ToolScriptManager try to add attribute CombineScript="false" in that and try..