Perhaps you need to recursively look for your control using FindControl and then call yourself?
private static Control FindNestedControl(string id, Control parent)
{
Control item = parent.FindControl(id);
if(item == null)
{
foreach(var child in parent.Controls)
{
item = child.FindNestedControl(id, child);
if(item != null)
{
return item;
}
}
}
return null;
}
And call it by passing the current instance of the page with:
Control item = FindNestedControl("bob", this);
This can be slow, so pay attention to this if there is a whole group of controls on the page :)
Another way to do this is to simply set the controls as properties in the base class:
public abstract class BasePage : Page
{
#region Properties
protected TextBox SomeTextBox
{
return this.textBox; }
}
#endregion
}
- :
public abstract class BasePage : Page
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.ConfigureControl(this.mainText);
this.ConfigureControl(this.nameDropDown);
this.ConfigureControl(this.someOtherControl);
}
protected virtual void ConfigureControl(Control control)
{
}
}
:
protected override void ConfigureControl(Control control)
{
switch(control.ID)
{
case "mainText":
TextBox mainText = (TextBox)control;
mainText.Text = "works";
break;
}
}
, , , . ..