<label> element in ASP.NET

  • Thread starter Thread starter Smokey Grindle
  • Start date Start date
S

Smokey Grindle

How can you correctly use the <label> element in asp.net? does the label
custom control corelate to this tag correctly in the same way in that if you
click it it will select the tied element? thanks
 
The <asp:Label> tag renders to a <span> in HTML and is most akin to a label
on a windows form. The <label> tag, in HTML, is hidden and provides a
wrapper to allow text to toggle a control. The two controls are NOT the
same.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
 
How can you correctly use the <label> element in asp.net?

Same as any other HTML element...
does the label custom control corelate to this tag correctly in the same
way in that if you click it it will select the tied element? thanks

If, by "label custom control" you are referring to the <asp:Label>
webcontrol, no - that renders a <span> tag.

BTW, <label> is not supported by all browsers, specifically Safari, the most
popular Mac browser...
 
I have this in my aspx page

<asp:Label ID="Label4" runat="server" AssociatedControlID="txtEmail"
Text="E-Mail Address:"></asp:Label><asp:TextBox ID="txtEmail"
MaxLength="200" Width="365px" runat="server"></asp:TextBox>



when it renders it renders as this

<label for="ctl00_ContentPlaceHolder1_txtEmail"
id="ctl00_ContentPlaceHolder1_Label4">E-Mail Address:</label><input
name="ctl00$ContentPlaceHolder1$txtEmail" type="text" maxlength="200"
id="ctl00_ContentPlaceHolder1_txtEmail" style="width:365px;" />
 
I have this in my aspx page

<asp:Label ID="Label4" runat="server" AssociatedControlID="txtEmail"
Text="E-Mail Address:"></asp:Label><asp:TextBox ID="txtEmail"
MaxLength="200" Width="365px" runat="server"></asp:TextBox>



when it renders it renders as this

<label for="ctl00_ContentPlaceHolder1_txtEmail"
id="ctl00_ContentPlaceHolder1_Label4">E-Mail Address:</label><input
name="ctl00$ContentPlaceHolder1$txtEmail" type="text" maxlength="200"
id="ctl00_ContentPlaceHolder1_txtEmail" style="width:365px;" />

Yes indeed.

According to MSDN
(http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.label.associatedcontrolid.aspx)
this is supported in v2.0 and v3.0 of the Framework
 
Back
Top