In label for attribute is not displaying client id of control

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

I am working on 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

    <asp:Label ID="lblFirstName" runat="server" AssociatedControlID="txtFirstname" Text="First Name"></asp:Label>

    Open in new window

    LVL 13

    Expert Comment

    You can do this by taking textbox instead of html textbox.
    LVL 17

    Expert Comment

    Use AssociateControlID property as @informaniac suggested

    For more details

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now