Inheriting from System.Web.UI.Page and System.Web.UI.UserControl

  • Thread starter Thread starter DanG
  • Start date Start date
D

DanG

Howdy,

On past .NET projects, I only had System.Web.UI.Page forms. One
application needed a set of functions to do processing against the
Page, Session and Request objects associated with the current Form. I
handled this by making a new class (BasePage) which inherits from
System.Web.UI.Page. Each form would then inherit from BasePage rather
than System.Web.UI.Page.

I am now on a project that has both System.Web.UI.Page and
System.Web.UI.UserControl forms. I want to do the same type of
BasePage processing for the UserControl screens, but I can't inherit
them from BasePage. Currently, I made two classes that are identical,
except that each inherit from the respective System.Web.UI object.
Obviously, I would like a single class that would handle both types of
forms, but I can't figure out the proper way to do it. I could use a
clue.

Thanks
Dan
 
UserControl is not page. So you cannot inherit your usercontrols from your
BasePage. In my understanding, what you want is to use functions in your
BasePage from those usercontrols. One way you can do is to cast use
usercontrol's contaniner page to BasePage. The use its functions:

BasePage parentPage = (BasePage)this.Page; // C#

Or

Dim parentPage As BasePage = CType(Me.Page, BasePage) ' VB.NET


HTH

Elton Wang
 
this would be multi-inheritance, which c# (and the clr) do not support. the
best you can do is create a common interface that both expose. the internal
routines should call common code.

-- bruce (sqlwork.com)
 
I was thinking ... (uh-oh)

The UserControls are on a form which inherits from System.Web.UI.Page.
Can I change that form to use BasePage, and then reference its
functions from the UserControl forms?

Using some of Elton's code, I tried adding
Dim parentPage As BasePage = CType(Me.Page, BasePage)
and then attempted to reference parentPage.<BasePage function>, but it
didn't work.
 
Doh!

I had the old BasePage functions still set to Protected. Had to make
them Public.

Thanks, guys
Dan
 
Back
Top