user control id's

user control id's

Post by adam » Fri, 21 Jun 2002 17:59:22



Hi,

I have a page which loads multiple instances of the same
user control. I want to be able to set the id property in
the code behind file, so that I can access the control in
client side java script.

It appears that asp.net automatically generates this id
property, which I can access with control.clientId, but
this is read only. If you set the property with
control.id="myControlId" asp.net tags other stuff on to
the front of this.

Is it possible to set the id (different for each instance
of the user control) to what I want rather than what
asp.net generates?

thanks

adam

 
 
 

user control id's

Post by Steve Liang ( » Sat, 22 Jun 2002 16:36:35


Hi Adam,

I think you can set the id number at the design time. It is not possible to
set it at runtime.

Regards,
Steve

This posting is provided "AS IS" with no warranties, and confers no rights.
"Got .Net?  http://www.gotdotnet.com"

 
 
 

1. User Control Instances and how .NET Prefixes control collection's ID's

Hey There.

Here's my problem:

I have a user control that has client-side code (via the <control
name>.attributes("onclick") = <whatever> property).  the "onclick" event is
going to trigger a javascript function to hide and show a <DIV>;  the
parameter I pass for this function is the <DIV> id ..

NOTE:  There's only ONE DIV in this usercontrol and it's named "pnlSubMenu"

eg.  whatever.attributes("onClick") = "showHideDiv('pnlSubMenu');"

Now, since this is in a user control, I want to be able to use this many
times over, but since I need to pass the DIV id to the "showHideDiv" js
function, I need to know how to access the id of the _currently
instantiated_ DIV.

if, for example, I have this user control 3 times in a webform, I notice
that .NET prefixes the id for the 'pnlSubMenu' for each instance with
something like "NavItem?" (so my final id for the instance would be
NavItem1_pnlSubMenu, NavItem2_pnlSubMenu, etc. for each instance of the user
control)

Is there a way to find out the prefix that's gonna be appended at runtime to
the UserControl's control collection?

(Did this question make ANY sense to you guys? :P  let me know... )

Max

2. Resample digital signal in C

3. Composite Control Prob - Multiple controls with the same ID '_ctl0' were found

4. London Electricity-Remember it was training issues?

5. Validation error: Unable to find control id referenced by the 'ControlToValidate' property

6. machine learning paper(s) available via WWW

7. The id 'ctrl1' is already used by another control

8. Access to protected inherited members

9. @ID' expects parameter @ID, which was not supplied

10. Multiple controls with the same ID '_ctl0' were found. FindControl requires that controls have unique IDs.

11. Multiple controls with the same ID 'WebForm1' were found. Trace requires that controls have unique IDs.

12. Multiple controls with the same ID 'frmRfq' were found. Trace requires that controls have unique IDs.