473,387 Members | 1,669 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,387 software developers and data experts.

Inheritng from .aspx page

Hi,


I have a newbie question for
(ASP.Net 2.0 framework) which is based on Design Pattern / Coding Trick

--> I need to :-
- Inherit one aspx page and its code (super abstract class) that in turn inherits System.Web.UI.Page
such that this page servers a base model for other aspx pages

--> Constraints
-- Want only Aspx page and not Code Page (like Base Class) !!!
Reason :- since the above abstract page is having user controls and points to the master page.

-- No Interface !!!
I dont want to implement this page as an Interface since there are some methods that will have the same code when overridden by the classes / aspx pages that may be implementing it causing duplicate code
So, an Abstract class model with abstract methods looks favorable

-- .Net only permits for single-level inheritance model

--> Some of the ways that I looked into are
-> Defining a Master Page ... but not sure about master page inheritence and this approach is not I like to have
-> Having a User Control .... which will have embedded user controls and loss of page theming ...
-> Thinking of having a base class ... which will define the aspx and html controls in the code .. not sure about this approach

--> Is there any better way of preserving the theme as well as achive some sort of multiple or 2 level inheritance with a better approach in ASP.Net 2.0 ?
(please correct me if I am missing something / Wrong)
Jan 22 '09 #1
7 4078
This is actually incorrect:

"-- .Net only permits for single-level inheritance model "

Your inheritance hierarchy can be as deep as you want, i.e., base < derived1 < derived2 < derived3

I think what you are getting at is that .Net only supports single inheritance, which means that a class can only inherit directly from one other class. i.e, you can't do base1, base2 < derived1

I think you're better off going with master page and user controls, though -- that's the way most people do it.
Jan 22 '09 #2
Frinavale
9,735 Expert Mod 8TB
VB.NET only allows you to inherit from one class; however, the class you inherit from can inherit from another class. C# allows you to inherit from more than one class.

You should really look into using a MasterPage.
A MasterPage is compiled with your ASPX Content Pages to provide a template that all pages use.

You can use UserControls as well if you'd like.....

You haven't really explained what you are trying to do.

Are you creating several pages in your site, and you'd like to have the same layout for all pages? Use a MasterPage to do this...also use a global external style sheet (CSS) to help you design your site's look and feel.

Are you creating one page that has several different components?
Use Web User Controls so that you can easily display more than one component on a page at a time.... If you are using a component in several different pages you should put it into a Web User Control so that it simplifies implementing and maintaining the component.
Jan 22 '09 #3
thanks podster and frinavale ...
---------------------------------------------------------------------------------------------
@Frinavale
---------------------------------------------------------------------------------------------
-> actually, i m trying to achieve a combination of both !!!
I am trying to create a Template - kind of page that uses
a) Already has all the Css (via one Master Page) and
b) links to combination of various User Controls

So that ... if I want to create other pages with the same model, I have to just inherit this page and pass different parameters from the subclass to get different types of say results like Custom-made Reports!!!

On One thought, I was thinking of having a aspx page very parallel to Base Pages . cs / .vb with all the above embedded in it and then try to inherit this page in the subclasses (.aspx and Code behind files) ... but am not sure how to go about this at this point
Jan 22 '09 #4
Frinavale
9,735 Expert Mod 8TB
Why do you need to inherit anything?

I do not see any reason why you want to inherit anything when you have MasterPages, UserControls and CSS at your disposal.

If you want to create any new pages using that mode, create a new Content Page that uses the MasterPage you've developed.....

You don't have to inherit anything.


Your pages should use instances of your UserControls where needed.
There's no reason why you want to have a UserControl in a base class if it isn't going to be used.
Jan 22 '09 #5
Hi Frinavale,

I wanted to inherit since I have lots of pages that have some commonality which is the same master page and same sets of user controls ....

the only thing varies is the parameters ; Considering Refactoring of the Code ... I wanted to create a - sort - of - <GOD> ASPX page that has Master page and the user controls and the variables ....

and most of the other pages will then call this page with the paramter they want so the code is drastically reduced in these child custom ASPX pages ... they just need to supply the right list of parameters ...
Jan 22 '09 #6
Frinavale
9,735 Expert Mod 8TB
I tend to use the K.I.S.S. (Keep It Small And Simple) approach when developing any application. Implementing a "God" Page is basically the opposite to that approach.

When you have such a massive class as the Base class you are going to have a hard time maintaining that class and the rest of them.

As soon as you need to add another parameter in the Base Class you're going to have to modify every other page just because one page requires it.

I would strongly recommend against this style, but to-each-their-own. If you're dead set on doing this, then the best of luck to you :)

If I were you, I'd put the common functionality that exists on every page in the master page and create User Controls for features that aren't required on every page but are used in more than one. I'd add user controls the pages that require them. Each page would remain it's own page and there would be no "God" page.


If there are functions that are required on more than one page that do the same thing, I tend to add them to a class (not a page) I call "Utils". This class is "NotInheritable"/"Sealed" and only contains Public Static/Shared functions so that I can easily call the functions throughout my code and pages.

-Frinny
Jan 23 '09 #7
NitinSawant
270 100+
hmm..

you should use Master Pages..

Creating a GOD page and inheriting from it
is similar to creating Master page!!
Jan 31 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Santa | last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx to increase the performance of my ASPX...
6
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html...
0
by: Santa | last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx to increase the performance of my ASPX...
11
by: tma | last post by:
I have the following HTML in use on my web page. I need it to show a graphic image on the page but do not know what to use in the codebehind to make the graphic appear. If I load the source url in...
2
by: WJ | last post by:
I have three ASPX pages: 1. "WebForm1.aspx" is interactive, responsible for calling a web site (https://www.payMe.com) with $$$. It is working fine. 2. "WebForm2.aspx" is non-interactive, a...
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
24
by: John Rivers | last post by:
ASPX which means ASPX pages, the code-behind concept, User Controls, Web Controls etc. is very poorly designed and makes it extremely hard to develop professional quality web applications. ASPX...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
3
by: =?Utf-8?B?QXJ1bmVzaCBNb2hhbg==?= | last post by:
Hello All: I have an ASPX A.ASPX where I am displaying realtime data using embedded ASPX page B.ASPX. When I go to next page/previous page from A.ASPX page, I am able to go to next/previous...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.