Page Inheritance

L

Leo

I would like to create a base page with some code and server controls on it and then inherit that page in all my other pages. I have tried in the codebehind changing
Inherits Systgem.Web.UI.Page
to
Inherits myBasePage

and in the HTML for the page.aspx changing
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="InheritanceText.TestForm"%>
to
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="InheritanceText.myBaseForm"%>

I would like the page that is inheriting from myBaseForm to inherit all the visual and server controls also. Is this possible in VS 2003 and if so what do I need to do?
 
P

Peter Rilling

This probably might not be as you would expect. Although the code that
initializes the controls might be inherited, the HTML is not.

To reuse layout, you might want to consider using usercontrols.

I would like to create a base page with some code and server controls on it
and then inherit that page in all my other pages. I have tried in the
codebehind changing
Inherits Systgem.Web.UI.Page
to
Inherits myBasePage

and in the HTML for the page.aspx changing
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb"
Inherits="InheritanceText.TestForm"%>
to
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb"
Inherits="InheritanceText.myBaseForm"%>

I would like the page that is inheriting from myBaseForm to inherit all the
visual and server controls also. Is this possible in VS 2003 and if so what
do I need to do?
 
E

Eliyahu Goldin

It is possible in ASP.NET 2.0 with MasterPages. You can start using it now if you are happy with beta.

Eliyahu

I would like to create a base page with some code and server controls on it and then inherit that page in all my other pages. I have tried in the codebehind changing
Inherits Systgem.Web.UI.Page
to
Inherits myBasePage

and in the HTML for the page.aspx changing
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="InheritanceText.TestForm"%>
to
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="InheritanceText.myBaseForm"%>

I would like the page that is inheriting from myBaseForm to inherit all the visual and server controls also. Is this possible in VS 2003 and if so what do I need to do?
 
J

John M Deal

If you are looking for something similar to the 2005 master pages in the
2002 and 2003 environments I would recommend looking into Paul Wilson's
master page article. Originally this was posted on MSDN but an updated
version of it can be found at:

http://authors.aspalliance.com/PaulWilson/Articles/?id=14

You can google for the original if you'd like. Anyway this is actually
quite easy to use, is very flexible, and give you the ability to
override areas of your master pages. Takes a bit of getting use to at
first, but works like a champ.

Have A Better One!

John M Deal, MCP
Necessity Software
 
R

Random

Actually, you can do just as you describe without going to MasterPages,
although that will make it easier. Yes, I've done it so that I can share
the extended Page class containing global functions that need access to the
current context. I couldn't get that to work globally otherwise. Also good
for enumerations and constants that you want available site-wide.


It is possible in ASP.NET 2.0 with MasterPages. You can start using it now
if you are happy with beta.

Eliyahu

I would like to create a base page with some code and server controls on it
and then inherit that page in all my other pages. I have tried in the
codebehind changing
Inherits Systgem.Web.UI.Page
to
Inherits myBasePage

and in the HTML for the page.aspx changing
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb"
Inherits="InheritanceText.TestForm"%>
to
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb"
Inherits="InheritanceText.myBaseForm"%>

I would like the page that is inheriting from myBaseForm to inherit all the
visual and server controls also. Is this possible in VS 2003 and if so what
do I need to do?
 

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

Top