DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 13 Aug 2007 10:32:43 +0100,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Rob Meade
          2    Riki
                 3    Rob Meade
          4    Ladislav Mrnka
                 5    Rob Meade


Page.FindControl   
Hi all,

I was wondering if you can help.  I have the need to find a control on the 
page for which I don't know all of the ID, this is because it is made up 
from several id's forming one new id.  Is there anyway to find this control 
with only part of the information (the part I have will definately be 
unique).

I was hoping that it might be possible to push a regular expression in the 
string part of the Page.FindControl - but I dont think I can.

I've tried iterating through all the controls on the page, but - well - it 
lies!  If I add Page.Controls to the watch it says there's five, if I then 
add .Item(3) - the html form control, and then add .Controls this is full of 
more controls...

Can anyone help me?

Regards

Rob
Date:Mon, 13 Aug 2007 10:32:43 +0100   Author:  

Re: Page.FindControl   
Rob Meade wrote:

> Hi all,
>
> I was wondering if you can help.  I have the need to find a control
> on the page for which I don't know all of the ID, this is because it
> is made up from several id's forming one new id.  Is there anyway to
> find this control with only part of the information (the part I have
> will definately be unique).
>
> I was hoping that it might be possible to push a regular expression
> in the string part of the Page.FindControl - but I dont think I can.
>
> I've tried iterating through all the controls on the page, but - well
> - it lies!  If I add Page.Controls to the watch it says there's five,
> if I then add .Item(3) - the html form control, and then add
> .Controls this is full of more controls...


You have to make a recursive loop.

I think that's the only solution here.

-- 

Riki
Date:Mon, 13 Aug 2007 13:10:17 +0200   Author:  

RE: Page.FindControl   
Hi Rob,
FindControl method is always related to current Naming container. So if you 
want to use plain ID as it is defined you will need to have reference to 
control which is naming container for controls you are looking for. 

You can also use whole unique ID from top level naming container (usually 
page) or part of unique ID - but again you have to relate it to proper naming 
container.

If unique ID of your control is built from several IDs it means it is in 
hierarchy of naming containers. Each container will add its id followed by 
separator (usually $) to final id of your control.

Say you have control with uniqueID ctl00$ctl00$ctl00$myLabel. You can find 
this control by calling Page.FindControl("ctl00$ctl00$ctl00$myLabel") or if 
you have reference to control ctl00$ctl00 (named for example myGridRow) you 
can call myGridRow.FindControl("ctl00$myLabel").  

Use tracing to see whole tree of controls including naming containers.

Regards,
Ladislav 

"Rob Meade" wrote:


> Hi all,
> 
> I was wondering if you can help.  I have the need to find a control on the 
> page for which I don't know all of the ID, this is because it is made up 
> from several id's forming one new id.  Is there anyway to find this control 
> with only part of the information (the part I have will definately be 
> unique).
> 
> I was hoping that it might be possible to push a regular expression in the 
> string part of the Page.FindControl - but I dont think I can.
> 
> I've tried iterating through all the controls on the page, but - well - it 
> lies!  If I add Page.Controls to the watch it says there's five, if I then 
> add .Item(3) - the html form control, and then add .Controls this is full of 
> more controls...
> 
> Can anyone help me?
> 
> Regards
> 
> Rob 
> 
> 
> 
Date:Mon, 13 Aug 2007 04:22:03 -0700   Author:  

Re: Page.FindControl   
"Riki" wrote...


> You have to make a recursive loop.
>
> I think that's the only solution here.


Yeah, thats what I thought - messy :o/

Thanks for your reply Riki,

Rob
Date:Tue, 14 Aug 2007 09:01:43 +0100   Author:  

Re: Page.FindControl   
"Ladislav Mrnka" wrote ...


> Say you have control with uniqueID ctl00$ctl00$ctl00$myLabel. You can find
> this control by calling Page.FindControl("ctl00$ctl00$ctl00$myLabel") or 
> if
> you have reference to control ctl00$ctl00 (named for example myGridRow) 
> you
> can call myGridRow.FindControl("ctl00$myLabel").
>
> Use tracing to see whole tree of controls including naming containers.


Hi Ladislav,

Thanks for the reply.

I should have been more clear in my post, its actually me making the 
multi-part id's for the controls, not .Net because they are in other 
controls etc....

I am using various ID's from my database content and using them in the id's 
of the controls.

Thanks for the information though - very useful.

Regards

Rob
Date:Tue, 14 Aug 2007 09:03:00 +0100   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us