Novice Developer
Novice Developer

Reputation: 4759

page child control

asp.net page is also a control. how can I access child control within page control?

this.page.?

Upvotes: 3

Views: 262

Answers (3)

Josh
Josh

Reputation: 44916

You can access it via the Controls Collection

Page.Controls

Recursive FindControls from Rick Strahl's Blog

public static Control FindControlRecursive(Control Root, string Id)
{
    if (Root.ID == Id)
        return Root;

    foreach (Control Ctl in Root.Controls)
    {
        Control FoundCtl = FindControlRecursive(Ctl, Id);
        if (FoundCtl != null)
            return FoundCtl;
    }

    return null;
}

Be careful with this however... This is not a method you want to be using inside a loop or anything.

Upvotes: 3

nickytonline
nickytonline

Reputation: 6981

  • Page.Controls
  • FindControl method

Upvotes: 4

Canavar
Canavar

Reputation: 48098

Try this :

Control childControl = Page.FindControl("YourControlsID");

Upvotes: 5

Related Questions