I don’t know if this has to do with how FindControl works or how scope works. But my base class is having a hard time seeing the fields of child classes. Currently I’m planning have the derived class set a property in the base class, but there are a lot of derived classes, so that isn’t a very attractive solution.
public class BasePage:Page
{
public void DoSomethingWithDerivedPageControl()
{
//foo is always null.
Control foo = FindControl("Foo");
}
}
public class DerivedPage : BasePage
{
//In real life, this is the code generated .aspx.designer.cs file.
protected Label Foo;
}
FindControldoesn’t use fields – it uses the controls which have been added to the page, and checks their ids.Presumably your control hasn’t been added to the page at the time when
DoSomethingWithDerivedPageControlis called.It would be helpful if you could tell us what you’re really trying to achieve… if all your derived types should have a control called
Foo, why not just put it in the base class to start with?