tag in asp: Label ASP.NET Control? I really like the HTML tag, which makes it very easy to see whic...">

Is it possible to simulate HTML <Label / "> tag in asp: Label ASP.NET Control?

I really like the HTML tag, which makes it very easy to see which label stands for which input element by checking its "for" attribute. You know, something like:

    <label for="txtInput"> Enter your name</label>
    <input type="text" id="txtInput" />

      

Is it possible to do something like this in the asp.net Label control so I can see what it means, what kind of input control? I couldn't see the attribute for this. Without expanding control?

Thank!

+2


source to share


3 answers


http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.label.associatedcontrolid.aspx

<asp:label AssociatedControlID="textbox1" runat="server" id="lblOne" />
<asp:textbox id="textbox1" runat="server" />

      



Not tested, but in these lines ...

+8


source


If you set the AssociatedControlID property to <asp: Label> it will write out HTML <label> instead of <span>



+2


source


AssociatedControlID works in .net 2+ in earlier versions, you need to do something like the following:

<label for="<%=textbox1.ClientID %>">label text</label><asp:textbox id="textbox1" runat="server" />

      

0


source







All Articles