可以指定标签文本以两种不同的方式显示:
方法一:
<asp:Label ID="Label1" runat="server"
Text="Enter search string (optional):" ></asp:Label>
这将显示:Enter search string (optional):
Label text can be set from your code using Label1.Text = "SomeText";
方法二:
<asp:Label ID="Label1" runat="server"
Text="Enter search string (optional):" >Please enter search string</asp:Label>
在这种情况下,Text 属性被忽略,它将显示:Please enter search string
在我看到的所有示例中都使用了方法 1。
什么时候有人会使用方法 2(如果有的话)?如何从方法 2 的代码中设置标签文本?
最佳答案
Text
属性直接赋给Label1.Text
。在标签的“内部文本”中写入会将 LiteralControl
添加到标签的 Controls
集合中。
不同之处在于您可以在标签中嵌套多个控件,而这不能通过 Text
属性完成。
例如:
<asp:Label runat="server">
<asp:Image runat="server" ImageUrl="/image.jpg" />Some text
</asp:Label>
关于c# - asp :Label tag的Text属性和内部文本有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24938238/