Render DateTime.Now directly on the ASPX page

I am trying to do the following directly on an aspx page, but not showing the date value. I do not want to do this from code. Am I missing something here? Pls offers.

<asp:Literal ID="ltrDate" Text='<% DateTime.Now.ToLongTimeString() %>' runat="server"></asp:Literal>

Even using a hash in the expression <% # DateTime.Now.ToLongTimeString ()%> does not work.

+5
source share
2 answers

When using a data binding expression such as <%# DateTime.Now.ToLongTimeString() %>, you must call Page.DataBind()(or ltrDate.DataBind(), if that is the only control of the data binding) your code-code (for example, in Page_Load).

+7
source

Literal , . , :

<%= DateTime.Now.ToLongTimeString() %>

, <%# xx %> <%$ %> .

. .

+16

All Articles