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



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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

QUICK TIP:
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"
        Text="Name:"
        AssociatedControlID="txtName"
    />
    <asp:TextBox id="txtName" runat="server" />
</form>

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: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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