Getting id's of composite controls

  • Thread starter Thread starter Chris Kennedy
  • Start date Start date
C

Chris Kennedy

I can't seem to get the id of the child controls of my composite control. I
can get the unique id but the id when I try to access it via the controls
collection comes back null. Do I need to add a form tag within the control
rather than on aspx parent page. Any ideas? Regards, Chris.
 
The form tag should only be on the aspx page - not on the composite or child controls. You can access the child controls by calling the FindControl method from the parent. For example, with two children Child1 and Child2 in Parent:
public class WebForm1 : System.Web.UI.Page
{
public System.Web.UI.UserControl Parent1;

private void Page_Load(object sender, System.EventArgs e)
{
Response.Write(Parent1.FindControl("Child11").ID.ToString());
Response.Write(Parent1.FindControl("Child21").ID.ToString());
}
}

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top