473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Impementing "Base" pages.

Hi all,

We have created some "Base" class pages for our WebForms and UserControls.
For instance, when we create a WebForm called "WebForm1.aspx", instead of
inheriting from "System.Web.UI.Page" we implement from our "Base" class page
which itself inherits from "System.Web.UI.Page" -- I know, pretty standard.
We do the same with our UserControls, instead they inherit from
"System.Web.UI.UserControl".

Now, there are some methods that we want to include in these "Base" class
pages -- we don't want them in a seperate class because we don't want to
have to make them Shared (Static), nor do we want to instantiate them each
time. However, currently we have to declare these in both our WebForm base
class and our UserControl base class.

Does anyone have any a good way to centralize these methods so that we don't
have to duplicate them, yet they are accessible in each base class page?

Additionally, we have a number of Property's declared in these pages which
get and set data in the session object. These are also currently
duplicated, and we'd like to store them somewhere central so that they are
accessible by both sets of base classes.

Hope this makes sense.

Thanks!

Wade
Jan 21 '06 #1
2 1686
Hi,

is it too ugly solution if you'd just provide a typed read-only Page
property (returning type of your base Page class) in your base user
control? That way, derived user controls could access the Page instance in
typed manner, and access the methods etc declared in base page class via
this typed property without the need to re-implement them,

The ugliness there is that it couples your UCs tightly to that specific base
page class. You are able to loosen it a bit,. if you separate these methods
to an interface (UC's typed property would then be of this interface type,
which would be required for page classes to implement), but that can also be
useless if the base page class is used throughout the entire project.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:Oo*************@TK2MSFTNGP12.phx.gbl...
Hi all,

We have created some "Base" class pages for our WebForms and UserControls.
For instance, when we create a WebForm called "WebForm1.aspx", instead of
inheriting from "System.Web.UI.Page" we implement from our "Base" class
page which itself inherits from "System.Web.UI.Page" -- I know, pretty
standard. We do the same with our UserControls, instead they inherit from
"System.Web.UI.UserControl".

Now, there are some methods that we want to include in these "Base" class
pages -- we don't want them in a seperate class because we don't want to
have to make them Shared (Static), nor do we want to instantiate them each
time. However, currently we have to declare these in both our WebForm
base class and our UserControl base class.

Does anyone have any a good way to centralize these methods so that we
don't have to duplicate them, yet they are accessible in each base class
page?

Additionally, we have a number of Property's declared in these pages which
get and set data in the session object. These are also currently
duplicated, and we'd like to store them somewhere central so that they are
accessible by both sets of base classes.

Hope this makes sense.

Thanks!

Wade

Jan 21 '06 #2
Assuming your base class for Pages is

BasePage
=======

public class MyBasePage : System.Web.UI.Page
{
public void SomeMethodToAccess()
{
Response.Write("SomeMethodToAccess() called...");
}
}

E.g this is the class serving as base class for your aspx pages (e.g maybe
as a base for the code-behind classes to serve general purposes)

Then the UC base class:

BAseUserControl
=============
public class BaseUserControl : System.Web.UI.UserControl
{
protected MyBasePage BasePage
{
get
{
return this.Page as MyBasePage;
}
}
}

Now your user control's can inherit from this and access the Page in typed
manner for example:

public partial class WebUserControl : BaseUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.BasePage.SomeMethodToAccess();
}
}
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi,

is it too ugly solution if you'd just provide a typed read-only Page
property (returning type of your base Page class) in your base user
control? That way, derived user controls could access the Page instance in
typed manner, and access the methods etc declared in base page class via
this typed property without the need to re-implement them,

The ugliness there is that it couples your UCs tightly to that specific
base page class. You are able to loosen it a bit,. if you separate these
methods to an interface (UC's typed property would then be of this
interface type, which would be required for page classes to implement),
but that can also be useless if the base page class is used throughout the
entire project.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Wade" <wwegner23NOEMAILhotmail.com> wrote in message
news:Oo*************@TK2MSFTNGP12.phx.gbl...
Hi all,

We have created some "Base" class pages for our WebForms and
UserControls. For instance, when we create a WebForm called
"WebForm1.aspx", instead of inheriting from "System.Web.UI.Page" we
implement from our "Base" class page which itself inherits from
"System.Web.UI.Page" -- I know, pretty standard. We do the same with our
UserControls, instead they inherit from "System.Web.UI.UserControl".

Now, there are some methods that we want to include in these "Base" class
pages -- we don't want them in a seperate class because we don't want to
have to make them Shared (Static), nor do we want to instantiate them
each time. However, currently we have to declare these in both our
WebForm base class and our UserControl base class.

Does anyone have any a good way to centralize these methods so that we
don't have to duplicate them, yet they are accessible in each base class
page?

Additionally, we have a number of Property's declared in these pages
which get and set data in the session object. These are also currently
duplicated, and we'd like to store them somewhere central so that they
are accessible by both sets of base classes.

Hope this makes sense.

Thanks!

Wade


Jan 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Alex Martelli | last post by:
I hesitate a bit to post this, but... on the Italian Python NG, somebody was asking whether there was any way to convert an integer number x into a string which represents it in an arbitrary base N...
11
by: Joseph Turian | last post by:
Fellow hackers, I have a class BuildNode that inherits from class Node. Similarly, I have a class BuildTree that inherits from class Tree. Tree includes a member variable: vector<Node>...
4
by: Gecko | last post by:
I noticed that every time I override a class member, the intellisense behavior is to automatically add a call to the base class of the overridden member such as: public override void...
6
by: SA | last post by:
Hi all: I have an object of a base class that needs to be cast to an object of a specialized class. What is the best way to do this? (I thought about creating a constructor in the specialized...
7
by: relient | last post by:
Question: Why can't you access a private inherited field from a base class in a derived class? I have a *theory* of how this works, of which, I'm not completely sure of but makes logical sense to...
2
by: qazmlp1209 | last post by:
class base { public: base() { } base(int number) { priNumber = number ;
3
by: Rob | last post by:
I have these classes (elided methods): class Base { public: Base(string name) {...} }; class Derived : public Base {
3
by: Ravi | last post by:
Is this the correct way to think of "base class"? The "base class" is a class from which other classes are derived. The "base class" will never be derived from another class.
18
by: Stephan Beal | last post by:
Hi, all! Before i ask my question, i want to clarify that my question is not about the code i will show, but about what the C Standard says should happen. A week or so ago it occurred to me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.