【发布时间】:2015-05-14 05:38:46
【问题描述】:
当我在 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 = "";
}
}
【问题讨论】:
-
这将是 JavaScript 计时器的工作,而不是服务器端计时器。
-
如果您使用的是 ToolScriptManager,请尝试在其中添加属性 CombineScript="false" 并尝试..一旦我收到此错误,我就得到了这个解决方案并且它有效..
-
是的,我正在为日历和更新面板使用 ajax 脚本
-
@jilu 你试过我的建议吗..
-
@Jilu 很高兴它有帮助..将它作为答案标记它解决了:)
标签: c# asp.net timer updatepanel