Chicharito
Chicharito

Reputation: 1440

Asp.Net(C#) Label Text inline

'>

ı need textbox text set DateTime.Now.ToLongDateString() how to make ? must inline

Upvotes: 0

Views: 7249

Answers (1)

Oded
Oded

Reputation: 499042

Don't use the <%#%> syntax (used for binding expressions):

<%# DateTime.Now.ToLongDateString() %>

But <%=%> (same as runat="server" with Response.Write):

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

Or <%:%> if in .NET 4.0 (same as runat="server" with Response.Write and HtmlEncode):

<%: DateTime.Now.ToLongDateString() %>

See this post of the differences between the different <%%> tags.

So, this should work:

<asp:TextBox ID="TextBox1" runat="server" Text="<%= DateTime.Now.ToLongDateString() %>"></asp:TextBox>

Alternatively, in your code behind you can set this directly (in your page load event handler, for example):

TextBox1.Text = DateTime.Now.ToLongDateString();

Upvotes: 6

Related Questions