controls on a base page not available?

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?
 
B

bruce barker

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));
 
P

Peter Young

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.
 
B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top