Blog Stats
  • Posts - 298
  • Articles - 0
  • Comments - 3114
  • Trackbacks - 0

 

Gah! Labels

Labels... labels everywhere!  Labels where there is no reason to have labels!

I seem to have developed a nasty habit over a year ago when I was building the first pilot of Easy Assets .NET where I made liberal use of the asp .net label control for all field labels and headings.

What a waste!


Feedback

# re: Gah! Labels

Gravatar

There is one fairly good reason to have labels - well for .NET 1.1 SP1 and above - associatedControlId which provides better accessibility and usability for your forms (so click on the text, have the caret focus on the field). This is invaluable for those using Text Readers since the label acts as a description for the form field...

3/11/2005 11:14 AM |

# re: Gah! Labels

Gravatar

You can do that with regular HTML labels if I'm not mistaken.  Still no need to use a server control.

3/11/2005 11:32 AM |

# re: Gah! Labels

Gravatar

Problem is knowing the associatedcontrolId - to do that you need to use a control that's aware of ClientIds...hence a server control...

3/11/2005 12:40 PM |

# re: Gah! Labels

Gravatar

<label id="Label1" for="Textbox1">blah:</label><asp:TextBox id="Textbox1" runat="server"></asp:TextBox>

<br>

<br>This isn't accessibility friendly?  If I click the label it puts the cursor in the textbox.  No server control for the label.  I'll admit some ignorance of how accessibility works.

3/11/2005 1:01 PM |

# re: Gah! Labels

Gravatar

It is...now try putting the label in a user control. Problem is in ASP.NET you can never be sure of the ClientId of a server control due to renaming when in a container which implements INamingContainer (user controls and most server controls). The example you've shown only works if you put the TextBox on an ASPX page - not in a user control...

3/13/2005 9:26 AM |

# re: Gah! Labels

Gravatar

Ah ha, I hadn't thought of that.  Mostly because I haven't had much in the way of logic/controls inside user controls in Easy Assets.  User controls contain the header/menu/footer/navigation.  Not any labels in those.

3/13/2005 11:21 AM |

# re: Gah! Labels

Gravatar

with 2.0 of the framework controls are rendered with strange id's that cannot be determined without using the clientid property ,

for example your Textbox1 id would render as something like ctl00_content_TextBox1

and so to get the label for correctly associated with the control you have to do it as a label server control.

this however is causing me problems with labels and user controls where I want to associate a label with a user control I cannot get the id of the sub control in the user control.

10/30/2006 9:52 AM |

Post a comment





 

Please add 7 and 6 and type the answer here:

 

 

Copyright © Eric Wise