controls on a base page not available?

  • Thread starter Thread starter Peter Young
  • Start date Start date
P

Peter Young

If I inherit from a custom base page, it seems that the controls on the base page are unavailable.

e.g.

public class basePage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink HyperLink1;

private void Page_Load(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine("HyperLink1 is null = " + String.Format("{0}", HyperLink1 == null));
}
...


public class WebForm1 : basePage
{
protected System.Web.UI.WebControls.TextBox TextBox1;

private void Page_Load(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine("TextBox1 is null = " + String.Format("{0}", TextBox1 == null));
}
...

This results in the following output:

HyperLink1 is null = True
TextBox1 is null = False

Why is the base page's HyperLink control not available?
 
you need code to create the control. either in the code behind, or on the
aspx page source (which will generate the code).

-- bruce (sqlwork.com)

Peter Young said:
If I inherit from a custom base page, it seems that the controls on the base page are unavailable.

e.g.

public class basePage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink HyperLink1;

private void Page_Load(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine("HyperLink1 is null = " +
String.Format("{0}", HyperLink1 == null));
}
...


public class WebForm1 : basePage
{
protected System.Web.UI.WebControls.TextBox TextBox1;

private void Page_Load(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine("TextBox1 is null = " +
String.Format("{0}", TextBox1 == null));
 
bruce barker said:
you need code to create the control. either in the code behind, or on the
aspx page source (which will generate the code).

How do you mean? The control is already sited on the base page.
 
the code like:

HyperLink1 = new System.Web.UI.WebControls.HyperLink(); // create
control

of course you will need to add it to the pages control collection to be
rendered.


-- bruce (sqlwork.com)
 
Back
Top