In label for attribute is not displaying client id of control

Posted on 2012-09-16
Medium Priority
Last Modified: 2012-09-17
Hi Experts,

I am working on ASP.net 2.0 using C#

In my label, I have for attribute, where I need control client id. I wrote code below:

<label id="lblFirstName" runat="server" for="<%= txtFirstname.ClientID %>">First Name</label>

After rendering, I see the below code
<label id="ctl00_ContentPlaceHolder1_uccontactus1_lblFirstName" for="&lt;%= txtFirstname.ClientID %>">First Name</label>

but I am expected:

<label id="ctl00_ContentPlaceHolder1_uccontactus1_lblFirstName" for="ctl00_ContentPlaceHolder1_uccontactus1_txtFirstname">First Name</label>

Please suggest, how to fix client id in for attribute

Question by:tia_kamakshi
LVL 20

Accepted Solution

informaniac earned 2000 total points
ID: 38403564
<asp:Label ID="lblFirstName" runat="server" AssociatedControlID="txtFirstname" Text="First Name"></asp:Label>

Open in new window

LVL 13

Expert Comment

by:Rahul Agarwal
ID: 38404445
You can do this by taking asp.net textbox instead of html textbox.
LVL 17

Expert Comment

ID: 38404628
Use AssociateControlID property as @informaniac suggested

For more details http://forums.asp.net/t/1660487.aspx/1

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question