简体   繁体   中英

Asp.Net(C#) Label Text inline

'>

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM