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

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
 
G

Guest

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
 
B

Bruce Barker

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)
 
D

DanG

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

DanG

Doh!

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

Thanks, guys
Dan
 

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

Top