Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control question for name attribute 1

Status
Not open for further replies.

euntair

Programmer
Sep 13, 2007
53
US

Thank you in advance.

When a System.Web.UI.WebControls.DropDownList is used is it possible to override the name attribute? Using the .ID will give both id and name attributes the same value. Using .Attribute for id and name will apply them only after .Net assigns a generated name attribute.

It would also be nice to know how to access the .Net generated name for that control at runtime.
 
Why do you need to override the name attribute?
It would also be nice to know how to access the .Net generated name for that control at runtime.
Do you mean from the code-behind or from .js?
 
Code-behind. If I supply the name, or know what the system generated, I could call an control directly instead of .js looping through the controls.
 
To access a control from the codebehind, you use the ID property. If the code is contained within another control, say a textbox, in a gridview, then you have to use the .FindControl() method to get a reference to it.
In order for us help you better, you need to provide more information.
 
The information I am looking for would be for setting up logic client-side. I am looking for a way to know and/or control the name attribute pre-render.
 
If you are using the 4.0 framework, there is an attribute you can set on the control - ClientIDMode="Static", then you can use the ID that is in the markup.
If you are using an earlier version, then you will have to use getElementbyId and use the ClientID of the control: var x = getElementById("<%= yourcontrol.clientid %>")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top