By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 2,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

HTML Page Shell/Template and BasePage Class

P: n/a
I have a site where most of the pages will have a common "shell" or layout. There will be an outer table which will hold HTML elements but which will *also* hold UserControls (Global Nav, etc.). Right now, all of the HTML and the @ Register directives for the shell's UserControls are copied onto each and every .ASCX page on the site

I find this kind of frustrating because it means that I have to change many files whenever I want to make chages to the actual framework of the shell itself (as opposed to the UserControls embedded *in* the shell)

If the shell contains UserContols which need to be accessible from individual page methods, etc., I can't hink of how to do this. Right now, all of the pages on the site *do* derive from a common "BasePage" class which inherits from "Page" but I don't really know how I could use that to do this.

Help???
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

From your description, you've defined a certain base page class which
contains some common UI layout and shells and most pages in your web
application will derived from it. Now, you found that
1. you had to write those @Register diretives in every derived page's page
template
2. Not sure how to retireve a certain UserControls and do some operations
on it in a certain page's function, yes?

As for these problems, here are my suggestions:
1. When want to add some common content( UI layout) in most pages which has
a common basepage, we can use the serverside include file to contains those
common page templates rather than write them(such as diretives or html
sources in each page). Here is the reference in MSDN:
#Server-Side Include Directive Syntax
http://msdn.microsoft.com/library/en...ver-sideinclud
edirectivesyntax.asp?frame=true

2. As for the second problem that retrieving a usercontrol on the page in a
certain function(base page or derived page). That does be a pain, because
in ASP.NET, if we want to retrieve a control's instance in page's control
collection, we need to know its exact postion in the page's control
hierarchy. And then use FindControl method to retrieve it via id. That 'll
be abit complex since you've defined many UserControls on a page and need
to retireve them at runtime from the page's control hierarchy. You need to
know what's the UserControl's parent server control and find it from its
collecton. You can turn on the page's trace
<@Page Trace="true" ..>
To have a look at the certain page's Control tree so as to confirm this.

In addtion, here are some certain tech articles in MSDN on designing a
page controller( a common base page class) in asp.net web app.

#Page Controller
http://msdn.microsoft.com/library/en...eController.as
p?frame=true

http://msdn.microsoft.com/library/en...eController.as
p?frame=true

Also, in the ASP.NET's new release (Whidbey, there is a new featrue called
"Master Page") , it 'll much improve our capability on designing a certain
common page pages not only on function but also on UI inheritance.

#Master Pages in ASP.NET Whidbey
http://msdn.microsoft.com/library/en...terpages.asp?f
rame=true

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #2

P: n/a
Hi,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.