kosnkov
kosnkov

Reputation: 5941

Show codebehinde in aspx

Hi i just open new page in VS and added one simple line, question why date time isn't showing? There is just blak page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <%# DateTime.Now.ToString() %>
    </div>
    </form>
</body>
</html>

Upvotes: 1

Views: 72

Answers (3)

driis
driis

Reputation: 164341

<%# ... %> is data-binding syntax, which basically means that the expression will not be evaluated until DataBind() is called. Since you do not call DataBind(), nothing gets printed.

The syntax for evaluating the expression immediately would be:

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

Upvotes: 5

Thomas C. G. de Vilhena
Thomas C. G. de Vilhena

Reputation: 14595

You can also use the equals sign for a shorter notation:

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

Upvotes: 2

Akash KC
Akash KC

Reputation: 16310

You could use:

<% Response.write(DateTime.Now.ToString()) %>

<%= is equivalent to Response.Write so you can use <%= too.

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

Upvotes: 3

Related Questions