using common code for aspx and ascx classes

V

Vladimír Kolesnik

Hi there,
does anybody know, how to create a class, which is can be inherited by both
aspx (System.Web.UI.Page) as well as by ascx (System.Web.UI.UserControl)
classes.
I have the bunch of same methods, which I want to reuse in both ascx and
aspx classes. Any idea how to do it?
Thanks for all your hints.
 
K

Kevin Spencer

Create a class that inherits System.Web.UI.Page, or
System.Web.UI.UserControl, add whatever code to it that you need to be
global to all Pages/UserControls, and inherit that class in your
Pages/UserControls.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
E

Eliyahu Goldin

Good suggestions. Alternatively, if for whatever reason it doesn't suit you,
you can make just a class library with static functions that will get the
reference to the control as a parameter.

Eliyahu
 
V

Vladimír Kolesnik

The solution you described I already knew, thanks anyway. Maybe I was not
clear enough describing the problem, I have class MyWebPage derived from
System.Web.UI.Page (aspx), where I have often used methods for example for
dealing with database connection etc. All aspx pages I derive from
MyWebPage, everything is fine. The problem is when I have ascx class
derived from System.Web.UI.UserControl and I want to use methods to get
connection to the database and some other methods that are placed in the
MyWebPage class. Do I have to make a class similar as MyWebPage just
inherited from System.Web.UI.UserControl, for example MyUserControl to be
able use these methods for all ascx classes? I think there should be a way
to pass the problem having same methods defined in two classes.
 
K

Kevin Spencer

Well, you can't inherit from more than one base class, so that's not a
possibility. You could certainly implement an Interface, which would require
both classes to implement the same properties/methods defined in the
Interace. You could create a class which has all the shared functionality,
and include that class as a property of both base classes.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top