ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

Use client-side validation
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

What Does That Label Control Label?

In ASP.NET 1.x the label control was pretty boring. It basically placed whatever text it was assigned inside a <span> tag and that was about it. This led many developers to realize you could get the same results using the literal control which doesn't add the annoying <span> tag.

In ASP.NET 2.0, the label control has been given a new lease on life with the inclusion of the AssociatedControlID property. This property allows you to associate the label control with the content that it is intended to describe. Take a look at the following code snippet.

<form id="myForm" runat="server">
    <asp:Label id="myLabel" runat="server"
    <asp:TextBox id="txtName" runat="server" />

Now there's no confusion about what the label describes. Better yet, this association is carried over to the HTML that is rendered as well. Instead of a <span> tag, the label will now be rendered as an HTML <label> tag instead. Not only is this rendering more accurate, it also has the added benefit that if a user clicks on the label, the associated control will automatically get focus. In the example above, clicking on the "Name:" text will automatically place the cursor in the textbox so the user can enter their name.

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers