Control ID's

  • Thread starter Thread starter Jill Graham
  • Start date Start date
J

Jill Graham

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
 
My web page loads the controls dynamically using
Page.LoadControl("~/myControls/myControl.ascx")

So you're doing:
1) Control loadedControl =
Page.LoadControl("~/myControls/myControl.ascx")

and then 2) Page.Controls.Add(loadedControl)?

I believe you have to do loadedControl.FindControl("content1") for it
to work, or alternatively
Page.FindControl("userControlID").FindControl("content1") where you've
set loadedControl.ID = "userControlID" explicitly as an extra step
between steps 1) and 2) above.

-Sam
 
Back
Top