By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

using common code for aspx and ascx classes

P: n/a
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.

Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
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.

"Vladimír Kolesnik" <ko******@seznam.cz> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
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.


Nov 18 '05 #2

P: n/a
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.

"Kevin Spencer" <ks******@takempis.com> píše v diskusním příspěvku
news:uD**************@tk2msftngp13.phx.gbl...
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.

"Vladimír Kolesnik" <ko******@seznam.cz> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
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.


Nov 18 '05 #3

P: n/a
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.

"Vladimír Kolesnik" <ko******@seznam.cz> wrote in message
news:#b**************@TK2MSFTNGP09.phx.gbl...
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.

"Kevin Spencer" <ks******@takempis.com> píše v diskusním příspěvku
news:uD**************@tk2msftngp13.phx.gbl...
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.

"Vladimír Kolesnik" <ko******@seznam.cz> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
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.



Nov 18 '05 #4

P: n/a
Thanks a lot. Your advice was exactly what I need.

"Kevin Spencer" <ks******@takempis.com> píše v diskusním příspěvku
news:uU*************@TK2MSFTNGP10.phx.gbl...
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.

"Vladimír Kolesnik" <ko******@seznam.cz> wrote in message
news:#b**************@TK2MSFTNGP09.phx.gbl...
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.

"Kevin Spencer" <ks******@takempis.com> píše v diskusním příspěvku
news:uD**************@tk2msftngp13.phx.gbl...
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.

"Vladimír Kolesnik" <ko******@seznam.cz> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
> 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.
>
>
>



Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.