Konstantin Zadiran
Konstantin Zadiran

Reputation: 1541

Is there any control in ASP.NET Web Forms, which is rendered in <label> html tag?

Is there any control in ASP.NET Web Forms, which is rendered in html tag on page rendering?

Upvotes: 1

Views: 516

Answers (3)

Jonathan Twite
Jonathan Twite

Reputation: 952

Similar to Konstantin Zadiran's answer, in the html:

<label id="lblLabel"><asp:Literal runat="server" ID="litLabelText"></asp:Literal></label>

and in the code behind:

litLabelText.Text = ...

Upvotes: 1

Kirk
Kirk

Reputation: 16265

You could use a Label control and the AssociatedControlId property.

<asp:Label id="lLabel" AssociatedControlId="tbMyField" Text="My field" runat="server" />
<asp:TextBox id="tbMyField" runat="server" Text="My field" />

This will render as

<label for="tbMyField">My field</label>
<input type="tbMyField" name="tbMyField" value="My field" />

Upvotes: 1

Konstantin Zadiran
Konstantin Zadiran

Reputation: 1541

It can be done with creating user control which contains property "Text" in code-behind and markup <label><%= Text %></label>

Upvotes: 1

Related Questions