Inheriting a Base class in a web form

P

Peter Cresswell

Hi guys/gals,

I'm using VS.net 2003 and having trouble with the following:

I am trying to inherit a base class into a web form, but VS will then not
allow me to add any ASP.NET controls using the designer. The base class does
derive from System.Web.UI.Page.

Here's a code snippet:

public class BaseAdminPage : System.Web.UI.Page

{}



public class ContactAdmin : BaseAdminPage

{

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}



Can anyone help?

Thanks,

Peter
 
É

Éric Moreau [VB MVP]

From http://www.asptoday.com/Content.aspx?id=1972

In any application, it is desirable for the interface to be consistent. In
web applications specifically, you want the user to feel that they are on
the same website as they move from page to page, having the same navigation,
color scheme, and layout on every page. In .NET Windows Forms, it is
possible to use visual inheritance to have the look and composition of one
form, inherit from another. Since each form is itself a class, it would make
sense that forms can inherit from each other. However, this capability is
not innate to ASP.NET Web Forms. While inheritance is supported, this is
limited to code inheritance. Methods and Properties can be inherited,
however one .aspx page cannot inherit the server controls, form elements,
images and HTML script from another base .aspx page.

--

HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
P

Philip Rieck

It's a limitation of the VS.NET designer. Many other extremely annoying
quirks are fixed in
VS.NET 2005 - and this is one of them.

Note that it's not entirely impossible to use asp.net inheritance with
visual studio, just extremely frustrating.

You'll need to do one of these:
1. use #if debug statements to "comment out" the inheritance during design
time. Yuck.
2. not use the vs.net designer (this is what I do)
3. wait for vs.net 2005
4. not use inheritance.

If you're trying for a common template, try using Paul Wilson's master pages
http://authors.aspalliance.com/PaulWilson/Articles/?id=14
 
P

Peter Cresswell

Thanks Philip.

I'm only just starting out with asp.net programming. You mentioned that
you do not use the VS.NET designer, can you recommend an alternative
that I could look at?

Peter
 

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