Попробуйте использовать элемент управления ASP.NET сервера (т.е. Label
), который обновляется, когда сервер делает загрузку страницы, как это:
Markup:
<asp:UpdatePanel>
...
<asp:Label id="LabelLastUpdated" runat="server" />
</asp:UpdatePanel>
Code-за:
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 для получения дополнительной информации.
UPDATE:
Чтобы использовать это сценарий главной страницы, где любое обновление страницы контента вызывает метку обновить, то попробуйте следующее: разметка
Master страницы:
<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
Для сценария мастер-страницы, где вы хотите содержание страницы сказать главную страницу для обновления, то попробуйте следующее: разметку
Master страницы:
<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()
вам нужно C Do ода для этого? –