ASP.Net inheritance (different view (page) per URL)

M

Mr Flibble

If I have a base page Default.aspx (and Default.aspx.cs). Can I have via
ASP.Net inheritance another page derived from Default.aspx(and .cs) as
it's base class and then override the Stylesheet declaration (amongst
other things)??

I have two pages that are identical bar the Stylesheet and so far I have
to maintain two pages to achieve this. It would be nice to maintain
just ONE page but have its various styles displayed under different URLs.

It must be said that I could have just one page and have a url of the
type http://localhost/Default.aspx?style=1 but although I'm not sure how
to implement this, I don't think it will achieve my end-goal since I
want each style to have it's own URL because I'm going to be using Basic
Authentication to lock down the different views.

Can anyone help?

Flibble
 
C

clintonG

So why not just set the Theme or StyleSheetTheme in the @Page directive for
the page you want to appear differently?

If your not using a Theme or StyleSheetTheme you should look at the new 2.0
HtmlHead class that allows us to write into the head element noting we have
to mark the head runat="server" which breaks XHTML validation but so what?

// use google...
htmlhead site:msdn2.microsoft.com

Then you can simply use logic in the Page_Load event to determine which
stylesheet to load.

Now backtracking, if you are going to use Themes with MasterPages changing
the Theme dynamically requires doing so in Page_PreInit which the MasterPage
does not support. (OdeToCode.com has excellent articles about MasterPages).

When using Page_PreInit a base class that inherits from the Page class
becomes practical...

// a base class signature
public class MyBaseClass : System.Web.UI.Page

Note all other content pages must then inherit from your base class...

// content page signature
public class _Default.aspx : MyBaseClass

How's that?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
 

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