Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7627213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:25:46+00:00 2026-05-31T05:25:46+00:00

When you set the AssociatedControlID property on a Label control, it renders a <label>

  • 0

When you set the AssociatedControlID property on a Label control, it renders a <label> HTML tag with its for attribute set to the target control’s ClientID:

<label id="Label" for="TextBox">Dat TextBox</label>
<input id="TextBox" name="TextBox" type="text">

I’ve made a server control that has a TextBox inside it and I would like for the label to render its for attribute to my control’s interior TextBox. My first thought was to point directly to my server control:

<asp:Label ID="AwesomeLabel" runat="server" AssociatedControlID="AwesomeControl">
    Check out my awesome control!</asp:Label>
<custom:MyControl ID="AwesomeControl" runat="Server" />

But that makes the for attribute point to the <span> that is rendered around the server control’s contents:

<label id="AwesomeLabel" for="AwesomeControl">Check out my awesome control!</label>
<span id="AwesomeControl">
    <input name="AwesomeControl$ct123" type="text"></span>

It seems as though AssociatedControlID sets the for attribute by simply getting the target control’s ClientID:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.label.associatedcontrolid.aspx

I don’t want to go into the page’s .aspx.cs to set this programmatically, because this server control is used frequently and I’d like its implementation to be as quick as possible.

Is there any other way to make Label tags render their for attributes to my server control’s interior TextBox, either in the .aspx markup or from my server control’s code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:25:47+00:00Added an answer on May 31, 2026 at 5:25 am

    Currently your span is the element which possesses the id you are point to and your input doesn’t have any ID.

    Give your input element an ID and change the label so it points to that ID.

    <asp:Label ID="AwesomeLabel" runat="server" AssociatedControlID="txtAwesomeControl">
        Check out my awesome control!</asp:Label>
    
    <span id="AwesomeControl">
        <input id="txtAwesomeControl" name="AwesomeControl$ct123" type="text" />
    </span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set for(AssociatedControlID) attribute using jQuery? I am trying something like
currently i've built a collapseControl which behaves similar to a label (associatedControlID) to control
I have a composite control that adds a TextBox and a Label control to
set a UIImageView.image property to a UIImage is unable add the image to the
set value of a property of an anonymous type using reflection / TypeDescriptor is
I've got a Login Control set to come up inside a jQuery dialog box.
set-itemproperty -path HKCU:Control Panel\Desktop -name WallPaper -value Zapotec.bmp I found this code online for
i'm trying to set a default button to my login control, and after reading
:set ic ignores the case. How do you unset this?
Set<Type> union = new HashSet<Type>(s1); union.addAll(s2); AND Set <Type> union = new HashSet<Type>(); union.addAll(s1);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.