Asp.Net(C#)标签文本内联 [英] Asp.Net(C#) Label Text inline
问题描述
'>
ı需要文本框文本集DateTime.Now.ToLongDateString()如何制作?必须内联
ı need textbox text set DateTime.Now.ToLongDateString() how to make ? must inline
推荐答案
不要使用<%#%>
语法(用于绑定表达式):
Don't use the <%#%>
syntax (used for binding expressions):
<%# DateTime.Now.ToLongDateString() %>
但是<%=%>
(与带有 Response.Write
的 runat ="server"
相同):
But <%=%>
(same as runat="server"
with Response.Write
):
<%= DateTime.Now.ToLongDateString() %>
或<%:%>
(如果在.NET 4.0中)(与 runat ="server"
相同,并带有 Response.Write
和 HtmlEncode
):
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.
因此,这应该可行:
<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();
这篇关于Asp.Net(C#)标签文本内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!