473,471 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inherit a code behind page?

20 New Member
Hi all,
I have two aspx pages:
Default.aspx with its code behind page of Default.aspx.vb
Home.aspx with its code behind page of Home.aspx.vb

The Default page in effect is just a template, the Home page will be the same but with some extra functionailty. I dont want to have to copy the code from the Default.aspx.vb to the Home.aspx.vb page since I assume there is a more efficient way.

Ive tried to inherit the Default code into the Home code like so:

Default.aspx.vb
Expand|Select|Wrap|Line Numbers
  1. Public MustInherit Class DefaultCode
  2.  
  3.     Inherits System.Web.UI.Page
  4.  
Home.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Home.aspx.vb" Inherits="DefaultCode" %>
  2.  
Home.aspx.vb
Expand|Select|Wrap|Line Numbers
  1. Partial Class Home
  2.  
  3.     Inherits DefaultCode
  4.  
Now that just doesnt seem to be working, it doesnt seem to recognising what the DefaultCode is when im telling it to inherit it.

If i move the Default.aspx.vb into the App_Code file (im using Visual Web Developer) Home.aspx.vb inherits DefaultPage but Home.aspx wont run, there loads of errors.

Thanks, Ash.
Mar 28 '08 #1
5 1573
nateraaaa
663 Recognized Expert Contributor
Have you thought about creating a user control that will be used on both pages? The user control would contain the common functionality of the two pages. To me this would be an easier solution.
Nathan
Mar 28 '08 #2
malav123
217 New Member
Ya it's true user controlls are very useful and best way to accomplish you desired task.....
Mar 28 '08 #3
balabaster
797 Recognized Expert Contributor
Um...am I missing something here? Wasn't the Master pages concept developed (at least in part) for this purpose? Put all your common code, stylesheet, etc etc in the Master page, when you create a new page, select the "Select master page" option and create page content...

Ben
Mar 28 '08 #4
Ashlewis
20 New Member
Thank you all.

I thought masterpages were just for the HTML side of things?
Ive never used one, ill try one out after ive tried using user controls, another thing ive never used, any idea on how they would work in my case? any help would be appreciated, thanks.
Mar 28 '08 #5
balabaster
797 Recognized Expert Contributor
User controls are fabulous when you want to dynamically use templates for objects on your page, when you build a user control, think of it somewhat like an active-x control or a class in that you can create properties which set/get values inside objects within that user control. The user control would hold code in its codebehind that pertains only to functions pertaining to that user control.

My personal opinion is that for templating whole pages, this isn't really the way to go - others may or may not disagree with me but I look at master pages, pages and user controls somewhat as a hierarchy. Where each of my user controls contains one or more controls/user controls; pages hold a bunch of user controls and a master page holds a template for a bunch of pages to provide centralized management of look and feel of your site, including global methods and scripts that should be available across the whole site.

As I said though, that's just my personal opinion, and doesn't mean that either way is more right or wrong than the other.
Mar 28 '08 #6

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

Similar topics

5
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a 2 page Tab Control for users to add a Job in my application. The first page is for them to choose which type of Job they would like. The type of Job...
5
by: Jeff | last post by:
Greetings I am beginning a web app. I am using C# aspx forms for my web pages. Is it possible to create/use one aspx file as a base from which to derive other aspx files? I can not get this to...
15
by: Ben Mann | last post by:
Hi there, I am starting on an ASP .Net project. I have some examples of using a base class for pages to inherit from to allow additional properties to be used by default. This seems like a good...
4
by: David | last post by:
I have trying to have a webform inherit controls from another form and can't get it to work Say I have a form that saves the person's demographic info. ****one.aspx**** //I have an object...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
6
by: mister.mwa | last post by:
Hello, I have the following problem: I have a class Foo, and a class Bar. I want Foo to inherit from Bar, but i want to put them in separate files Foo.vb and Bar.vb. Then i will use the Foo...
2
by: ad | last post by:
We can inherit a class. But if the class is the code behind, when we inherit it , can we inherit it's aspx ahead together ?
2
by: Randall Parker | last post by:
I've noticed that C# can only inherit from a single class. At the same time, the CodeBehind in an aspx.cs file inherits from Page. So what do you all do to reuse code in .aspx.cs classes? ...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.