Render DateTime.Now directly in the ASPX page

前端 未结 2 1421
感情败类
感情败类 2021-02-10 00:35

I am trying to do the following directly into the aspx page but it is not showing the date value. I dont want to do it from the code behind. Am i missing something small here? P

2条回答
  •  误落风尘
    2021-02-10 01:08

    If you do not need to access the value of the Literal control from the code-behind, then there is no need to use it. Instead, you can just use the following expression in your page directly where you want to print the date:

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

    With server controls, you can only put either static text, databinding expressions <%# xx %>, or expression builders <%$ %> inside the property values in the page markup.

    See this related question for more details about each approach.

提交回复
热议问题