javascript - "Last refresh"更新面板后的消息

标签 javascript html asp.net vb.net

我似乎无法准确找到我需要的东西,所以我会询问。

我有一个页面,该页面将使用 ASP:Updatepanel 和timer_tick 事件每 5-10 分钟左右自动更新一次。我只是在寻找类似以下内容的消息:

    Last refresh was at:
    <script>document.write(document.lastModified);</script>

或者类似的东西。 有什么建议吗?

最佳答案

尝试使用 ASP.NET 服务器控件(即 Label),该控件会在服务器加载页面时更新,如下所示:

标记:

<asp:UpdatePanel>
    ...
    <asp:Label id="LabelLastUpdated" runat="server" />
</asp:UpdatePanel>

隐藏代码:

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

注意:“F” 是完整的日期/时间模式(长时间)。阅读 Standard Date and Time Format Strings了解更多信息。

<小时/>

更新:

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

母版页的标记:

<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
<小时/>

对于母版页场景,您希望内容页告诉母版页进行更新,请尝试以下操作:

母版页的标记:

<html>
    <head>

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

母版页的代码隐藏:

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()

关于javascript - "Last refresh"更新面板后的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19960460/

相关文章:

javascript - 禁用表单提交按钮但发布按钮值

javascript - 我怎样才能对这段代码进行按键操作?

c# - 使用C#、Asp.net向Excel写入大量数据

asp.net - 将服务器中的所有 webapp 置于离线状态

javascript - 获取 Javascript 中其他位置的偏移量

javascript - 用于压缩 javascript 和缩小图像的 Windows 程序

javascript - 使用 URL 中没有 # 的 anchor 滚动

javascript - 使用 ViewBag - asp.net mvc

javascript - BigInt 的对数

更改事件后的 Javascript 回调具有部分页面刷新