qualify base class members from derived class

  • Thread starter Thread starter StephenRichter
  • Start date Start date
S

StephenRichter

I have a base class:

namespace ac {
public class BasePage : System.Web.UI.Page
{
private string mPageTitle ;
private string mPageUrl ;

public BasePage( )
{
}

public string PageTitle
{
get { return mPageTitle ; }
set { mPageTitle = value ; }
}
}
} // end namespace ac

here is a class I derive from the base class:
public class Admin_LoadMaster : ac.BasePage
{

private void Page_Load(object sender, System.EventArgs e)
{
string Title = BasePage.PageTitle ; // <===== ERROR
}
}

In my class Admin_LoadMaster, I want to refer to public members of the
base class as a qualified name:
BasePage.PageTitle

but I get an error saying I am using BasePage as if it was a static
class, and PageTitle is not a static member.

The Microsoft .NET class code can do it:

public class Admin_LoadMaster : System.Web.UI.Page
{
public void Page_Load(object sender, System.EventArgs e)
{
if ( Page.IsPostBack == false )
{
}
}
}

"Page" is the class in System.Web.UI.Page and Page.IsPostBack is an
object instance member function. How can I best qualify my references
to the base class members?

thanks,
-Steve
 
I have a base class:

namespace ac {
public class BasePage : System.Web.UI.Page
{
private string mPageTitle ;
private string mPageUrl ;

public BasePage( )
{
}

public string PageTitle
{
get { return mPageTitle ; }
set { mPageTitle = value ; }
}
}
} // end namespace ac

here is a class I derive from the base class:
public class Admin_LoadMaster : ac.BasePage
{

private void Page_Load(object sender, System.EventArgs e)
{
string Title = BasePage.PageTitle ; // <===== ERROR
}
}
Try..
Base.PageTitle


In my class Admin_LoadMaster, I want to refer to public members of the
base class as a qualified name:
BasePage.PageTitle

but I get an error saying I am using BasePage as if it was a static
class, and PageTitle is not a static member.

The Microsoft .NET class code can do it:

public class Admin_LoadMaster : System.Web.UI.Page
{
public void Page_Load(object sender, System.EventArgs e)
{
if ( Page.IsPostBack == false )
{
}
}
}

"Page" is the class in System.Web.UI.Page and Page.IsPostBack is an
object instance member function. How can I best qualify my references
to the base class members?

thanks,
-Steve
 
I have a base class:
...

but I get an error saying I am using BasePage as if it was a static
class, and PageTitle is not a static member.

That is correct. Calling BasePage.Something will only work if Something is
static. You could use either base.Something, this.Something or just call
Something on it's own.

Michael
 
Michael said:
That is correct. Calling BasePage.Something will only work if Something is
static. You could use either base.Something, this.Something or just call
Something on it's own.

Michael

ok, thanks John, thanks Michael. "base" will work find.

any idea how the Microsoft System.Web.UI.Page class allows somethink
like "Page.IsPostBack"?

public class Admin_LoadMaster : System.Web.UI.Page
{
public void Page_Load(object sender, System.EventArgs e)
{
if ( Page.IsPostBack == false )
{
}
}
}

Isnt "Page" a class name and "IsPostBack" is a non static property?

-Steve
 
any idea how the Microsoft System.Web.UI.Page class allows somethink

Isnt "Page" a class name and "IsPostBack" is a non static property?

That's true but the Page has a Page property that takes precedence (not sure
of the correct word). It looks like any control you put on the page inherits
from Control, which has a page property. The idea being you can do something
like myButton1.Page to get an instance to the webpage. Because the webpage
itself inherits from Control it also gets this property even though it only
returns an instance of itself. So doing Page.IsPostback is like doing
this.Page.IsPostback which is probably less efficient than it could be and
not very intuitive. It's probably better to just do this.IsPostback or just
IsPostback although I'd prefer the first because it is more self
documenting.

With regards to using base.PageTitle you might be better off doing
this.PageTitle I think (depending on your situation). If you override
PageTitle then base.PageTitle will always call the PageTitle in the base
class, which might not be what you want.

Cheers,
Michael
 
Michael said:
That's true but the Page has a Page property that takes precedence (not sure
of the correct word). It looks like any control you put on the page inherits
from Control, which has a page property. The idea being you can do something
like myButton1.Page to get an instance to the webpage. Because the webpage
itself inherits from Control it also gets this property even though it only
returns an instance of itself. So doing Page.IsPostback is like doing
this.Page.IsPostback which is probably less efficient than it could be and
not very intuitive. It's probably better to just do this.IsPostback or just
IsPostback although I'd prefer the first because it is more self
documenting.

With regards to using base.PageTitle you might be better off doing
this.PageTitle I think (depending on your situation). If you override
PageTitle then base.PageTitle will always call the PageTitle in the base
class, which might not be what you want.

just like c++. that I can understand.
Cheers,
Michael

I have to contemplate all of this, but I have no doubt you have
imparted much truth with your words! Thanks.

-Steve
 
Back
Top