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

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

Post by Max Quagliott » Thu, 16 Jan 2003 07:54:29



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

 
 
 

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

Post by dip » Thu, 16 Jan 2003 09:21:16


I am not sure if I understood the question completely -
but you can take a look at the ClientID property to
identify the name of the control, contained in a user
control, in client script .

- dip

Quote:>-----Original Message-----
>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
Quote:>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
Quote:>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
Quote:>control)

>Is there a way to find out the prefix that's gonna be

appended at runtime to
Quote:>the UserControl's control collection?

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

>Max

>.


 
 
 

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

Post by Jesse Ezel » Thu, 16 Jan 2003 14:07:08


control.ClientID.Replace(":", "_");

--Jesse

 
 
 

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

Post by Max Quagliott » Fri, 17 Jan 2003 00:55:11


Thank you very much.  This is exactly what I was looking for :)


Quote:

> I am not sure if I understood the question completely -
> but you can take a look at the ClientID property to
> identify the name of the control, contained in a user
> control, in client script .

> - dip

> >-----Original Message-----
> >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

> >.

 
 
 

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

Hi folks,

The situation:
I have a custom ASP.NET server control that contains
multiple custom server controls.  These controls
themselves contain other standard and custom server
controls.

The problem:
When I implement the INamingContainer on the top-most
container server control, I get the error about having
multiple controls with the same ID.  When I simply
implement the INamingContainer on the contained child
controls ... it works fine.

What gives?  Can anyone explain why this is happening and
how to resolve the issue?  The primary reason that I want
to be able to use the INamingContainer at the top level
lies in the fact I may want to include it in another
custom control somewhere down the line.

Anyways, any help would be much appreciated.

Thanks - wg

2. Good FrontPage 98 book?

3. user control id's

4. Fatal Error during boot

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

6. Best price on the net CD-R 74 Minute Gold $2.99 Retail package - no rebates no gimmics no surcharges

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

8. Frontpage Providers

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

10. there's a control's ItemTemplate repeater collection?

11. Referring to Controls' properties in Controls Collection

12. 'Collection' is ambiguous in the namespace 'VBA'

13. User control 'global' events