|
How to find a control when using Master Pages |
|
|
|
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 )
|