I have to show date and timer on my project . and i am using the code :
我必须在我的项目上显示日期和定时器。我正在使用代码:
<asp:ScriptManager ID="sc2" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="UpdateTimer" runat="server" OnTick="UpdateTimer_Tick" Interval="1000"></asp:Timer>
<asp:Label runat="server" ID="DateStampLabel"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
but when i run on the local . it postback every seconds and after that timer stops . any idea to correct the code.
但是当我在当地跑步的时候。它每秒钟回发一次,然后计时器停止。任何想更正代码的想法。
C# Code:
c#代码:
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
2 个解决方案
#1
3
I am not sure whats wrong with your code, but try this below code if it can help you.
我不知道您的代码有什么问题,但是如果可以帮助您,请尝试下面的代码。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000"></asp:Timer>
<h3 class="bp-header__title">Time : <font color="red" size="4px"><asp:Label ID="lbl_Time" runat="server" Text="Label" Font-Bold="false" Font-Names="Digital-7 Mono"></asp:Label></font></h3><br />
</ContentTemplate>
</asp:UpdatePanel>
#2
0
I got the sample works by the following code
我通过下面的代码得到了这个示例
.aspx:
是:
<html>
<head>
</head>
<body>
<form id="frm" runat="server">
<asp:ScriptManager ID="sc2" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="UpdateTimer" runat="server" OnTick="UpdateTimer_Tick" Interval="1000"></asp:Timer>
<asp:Label runat="server" ID="DateStampLabel"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
.aspx.cs
.aspx.cs
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
If the page is refreshing during postback, that may be because some javascript error on your page, sometime javascript exception in other section will break the .NET async postback. If your label is not updating, you may want to check if there are any Response.Write
, Response.Filter
, Server.xxx
in your Page_Load
/Tick
event, since the ajax is returning anything you wrote to response, you may encountered The message received from the server could not be parsed.
message.
如果在回发期间页面正在刷新,这可能是因为页面上出现了一些javascript错误,其他部分中的javascript异常会破坏. net async回发。如果您的标签没有更新,您可能需要检查是否有任何响应。写,响应。过滤器,服务器。在Page_Load/Tick事件中,由于ajax返回您编写的任何响应,您可能会遇到无法解析从服务器接收到的消息。消息。
#1
3
I am not sure whats wrong with your code, but try this below code if it can help you.
我不知道您的代码有什么问题,但是如果可以帮助您,请尝试下面的代码。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000"></asp:Timer>
<h3 class="bp-header__title">Time : <font color="red" size="4px"><asp:Label ID="lbl_Time" runat="server" Text="Label" Font-Bold="false" Font-Names="Digital-7 Mono"></asp:Label></font></h3><br />
</ContentTemplate>
</asp:UpdatePanel>
#2
0
I got the sample works by the following code
我通过下面的代码得到了这个示例
.aspx:
是:
<html>
<head>
</head>
<body>
<form id="frm" runat="server">
<asp:ScriptManager ID="sc2" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="UpdateTimer" runat="server" OnTick="UpdateTimer_Tick" Interval="1000"></asp:Timer>
<asp:Label runat="server" ID="DateStampLabel"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
.aspx.cs
.aspx.cs
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
If the page is refreshing during postback, that may be because some javascript error on your page, sometime javascript exception in other section will break the .NET async postback. If your label is not updating, you may want to check if there are any Response.Write
, Response.Filter
, Server.xxx
in your Page_Load
/Tick
event, since the ajax is returning anything you wrote to response, you may encountered The message received from the server could not be parsed.
message.
如果在回发期间页面正在刷新,这可能是因为页面上出现了一些javascript错误,其他部分中的javascript异常会破坏. net async回发。如果您的标签没有更新,您可能需要检查是否有任何响应。写,响应。过滤器,服务器。在Page_Load/Tick事件中,由于ajax返回您编写的任何响应,您可能会遇到无法解析从服务器接收到的消息。消息。