ASP.NET Web 表单中是否有任何控件呈现在 <label> html 标记中?
Is there any control in ASP.NET Web Forms, which is rendered in <label> html tag?
ASP.NET Web Forms 中是否有任何控件,在页面呈现时呈现在 html 标记中?
可以通过创建在代码隐藏和标记 <label><%= Text %></label>
中包含 属性 "Text" 的用户控件来完成
您可以使用 Label
控件和 AssociatedControlId
属性。
<asp:Label id="lLabel" AssociatedControlId="tbMyField" Text="My field" runat="server" />
<asp:TextBox id="tbMyField" runat="server" Text="My field" />
这将呈现为
<label for="tbMyField">My field</label>
<input type="tbMyField" name="tbMyField" value="My field" />
类似于 Konstantin Zadiran 的回答,在 html:
<label id="lblLabel"><asp:Literal runat="server" ID="litLabelText"></asp:Literal></label>
在后面的代码中:
litLabelText.Text = ...
ASP.NET Web Forms 中是否有任何控件,在页面呈现时呈现在 html 标记中?
可以通过创建在代码隐藏和标记 <label><%= Text %></label>
您可以使用 Label
控件和 AssociatedControlId
属性。
<asp:Label id="lLabel" AssociatedControlId="tbMyField" Text="My field" runat="server" />
<asp:TextBox id="tbMyField" runat="server" Text="My field" />
这将呈现为
<label for="tbMyField">My field</label>
<input type="tbMyField" name="tbMyField" value="My field" />
类似于 Konstantin Zadiran 的回答,在 html:
<label id="lblLabel"><asp:Literal runat="server" ID="litLabelText"></asp:Literal></label>
在后面的代码中:
litLabelText.Text = ...