Saturday, 06 September 2008
DotNetSpace, Asp.net 2.0 tutorials and code examples. ajax, log4net...
Home arrow Articles arrow General Articles arrow How to find a control when using Master Pages
 
Main Menu
Home
Articles
News
Links
Search








BiraJones




How to find a control when using Master Pages Print E-mail
Tuesday, 14 November 2006

This article shows how to find a Control when using Master Pages in Asp.NET 2.0.

Sometimes is very common the need to find a control when using MasterPages,
or when you are trying to find a control inside some component.

This code below searches for a control in the page hierarchy of controls.

protected void doSomething()
{
    Label label = (Label) FindControlRecursive(this.Master, "FieldNameID");
    label.Text = texto;
}

public 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;
}

Last Updated ( Wednesday, 15 November 2006 )
 
< Prev   Next >
Popular
Polls
-->*/?>

Which language will you choose for coding with Visual Studio .NET?
 
-->*/?>

Is ASP.NET better than Java / JSP frameworks?
 

© 2008 DotNetSpace
Joomla! is Free Software released under the GNU/GPL License.