Javascript updatepanel之后的“上次刷新”消息

Javascript updatepanel之后的“上次刷新”消息,javascript,html,asp.net,vb.net,Javascript,Html,Asp.net,Vb.net,我似乎找不到我需要的东西,所以我会问的 我有一个使用ASP:Updatepanel和timer_tick事件每隔5-10分钟左右自动更新一次的页面。我只是在寻找这样一条信息: Last refresh was at: <script>document.write(document.lastModified);</script> 或者类似的。 有什么建议吗?尝试使用ASP.NET服务器控件,即在服务器加载页面时更新的标签,如下所示: 标记: <asp

我似乎找不到我需要的东西,所以我会问的

我有一个使用ASP:Updatepanel和timer_tick事件每隔5-10分钟左右自动更新一次的页面。我只是在寻找这样一条信息:

    Last refresh was at:
    <script>document.write(document.lastModified);</script>
或者类似的。
有什么建议吗?

尝试使用ASP.NET服务器控件,即在服务器加载页面时更新的标签,如下所示:

标记:

<asp:UpdatePanel>
    ...
    <asp:Label id="LabelLastUpdated" runat="server" />
</asp:UpdatePanel>
注意:F是完整的日期/时间模式长时间。阅读了解更多信息

更新:

要使用这是母版页场景,其中任何内容页刷新都会导致标签更新,请尝试以下操作:

母版页的标记:

<html>
    <head>

    </head>
    <body>
        ... Existing content ...
        <asp:Label id="LabelLastUpdated" runat="server" />
    </body>
</html>
<html>
    <head>

    </head>
    <body>
        ... Existing content ...
        <asp:Label id="LabelLastUpdated" runat="server" />
    </body>
</html>
对于希望内容页通知母版页更新的母版页场景,请尝试以下操作:

母版页的标记:

<html>
    <head>

    </head>
    <body>
        ... Existing content ...
        <asp:Label id="LabelLastUpdated" runat="server" />
    </body>
</html>
<html>
    <head>

    </head>
    <body>
        ... Existing content ...
        <asp:Label id="LabelLastUpdated" runat="server" />
    </body>
</html>
在内容页的代码隐藏中:

Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
    ' Do update of data here and set last updated label to current time
    LabelLastUpdated.Text = "Last refresh was at: " & DateTime.Now.ToString("F")
End Sub
Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
    ' Do update of data here and set last updated label to current time
    LabelLastUpdated.Text = "Last refresh was at: " & DateTime.Now.ToString("F")
End Sub
Sub UpdateLastUpdatedLabel()
    ' A content page is telling the last updated label to be set 
    ' to the current time
    LabelLastUpdated.Text = "Last refresh was at: " & DateTime.Now.ToString("F")
End Sub
在Page_Load或任何其他事件中,您希望将其用作更新母版页标签的触发器,请执行以下操作:

' Get a reference to the master page
Dim masterPage = DirectCast(Page.Master, YourMasterPageClassName)

' Now you can call the master page's UpdateLastUpdatedLabel method
' which will update the label's text to the current date/time
masterPage.UpdateLastUpdatedLabel()

请尝试以下代码,该代码将定期更新

在aspx页面中:

<asp:ScriptManager runat="server" id="ScriptManager1">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" id="UpdatePanel1">
  <ContentTemplate>
    <asp:Timer runat="server" id="Timer1" Interval="10000" OnTick="Timer1_Tick"></asp:Timer>
   <asp:Label runat="server" Text="Page not refreshed yet." id="LabelLastUpdated">
   </asp:Label>
  </ContentTemplate>
</asp:UpdatePanel>

你需要代码吗?我想这不是他想要的东西!这正是我要找的。我可以找到一些方法让它在我的当前页面上工作,但是如果我想加入,比如母版页,我该怎么做?@bender54-将标签放入母版页标记中,并让母版页的页面加载更新标签控件。如果任何内容页导致回发,这将更新标签。我有一个在母版页中使用标签的单独示例,以及内容页调用的方法来实际更新标签。请参阅更新的答案。@bender54-如果可以,请随时投票支持此答案:-我正要回来再次感谢母版页的更新,它很漂亮。我会向上投票,但我没有代表,我会提醒自己,当我到那里的时候。