当我在localhost中运行应用程序时,asp.net中的计时器工作,当我上传并检查在线计时器时,只是不起作用。
当用户点击“请求项目”按钮时,我有条件,在标签中,消息应显示为“已成功提交”,否则显示“有些错误消息”。所以,我做的是,我创建了一个更新面板,在里面我放置了一个提交按钮,其中2个标签用于成功消息,另一个用于显示错误消息。还有一个计时器控件,我已经设置了2秒钟,只显示2秒钟的信息并隐藏它们。
这是我的代码:
<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>
以下是在“请求项目”按钮下触发定时器控制的代码。
lblSuccess.Visible = true;
lblSuccess.Text = "Records Successfully Saved!";
Timer1.Enabled = true;
以下是计时器刻度事件下的代码。
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 = "";
}
}
答案 0 :(得分:1)
如果您使用ToolScriptManager
尝试在其中添加属性CombineScript="false"
并尝试..