Groups | Blog | Home
all groups > asp.net building controls > april 2004 >

asp.net building controls : control ID's


ccallen
4/29/2004 8:14:51 AM
Try setting the parent control's (myControl) id in the containing page.

Example:
mc = Page.LoadControl("~/myControls/myControl.ascx")
mc.ID = "MyControl1"

If you place the mc into a someother control (ie. PlaceHolder), then you
will need to take that into account when building a path to it and its
children.

ccallen

[quoted text, click to view]

Jill Graham
4/29/2004 4:16:47 PM
Hi,

My web page loads the controls dynamically using
Page.LoadControl("~/myControls/myControl.ascx")

The control myControl.ascx contains several controls with following ID's :
"_content1", "_content2", "_content3", ...

Once the control myControl.ascx has been loaded into the web page, the ID's
have been changed : "_ctl0:_content1", "_ctl1:_content2", ...
and the method Page.FindControl("_control1") returns nothing !

Does anybody know how I can continu to use the Page.FindControl method ?

Jill


Fred Hirschfeld
4/29/2004 6:28:04 PM
You actually need add public properties (or methods) to you control to
access the values in the embedded controls.

Fred

[quoted text, click to view]

Victor Garcia Aprea [MVP]
5/1/2004 1:32:12 AM
Hi Jill,

If you're looking for a child control of your usercontrol, and you're
starting the search at the page, you'll need to do:
[C#]
FindControl ("YourUserControlID:YourChildID");

Note the ':' syntax to help the FindControl method in finding your control.

Let me know if this is what you're after or not,

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

[quoted text, click to view]

AddThis Social Bookmark Button