page templates driving me to the brink of suicide

  • Thread starter Thread starter Mitch
  • Start date Start date
M

Mitch

I'm trying to use page inheritance so that I can derive all web pages from a
template. There are a bunch of examples at this site
http://authors.aspalliance.com/PaulWilson/Articles/?id=1, but strangely
enough, not a single one works with my design.

My format is quite simple: large table direcly under the <HTML> tag contains
a header usercontrol, a left side menu usercontrol and then page content.
Here is a simplified representation of my template design (you should be
able to paste this into a blank html doc):

<%@ Page language="c#" Codebehind="Template.aspx.cs" AutoEventWireup="false"
Inherits="StemCellPolitics._Template" %>
<%@ Register TagPrefix="uc1" TagName="Header" Src="_Header.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Menu" Src="_Menu.ascx" %>
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE>Default</TITLE>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<table id="tbl" cellSpacing="0" cols="3" cellPadding="0" width="800"
border="0">
<tr>
<td colSpan="3">
<uc1:header id="Header1" runat="server"></uc1:header></td>
</tr>
<tr>
<td vAlign="top" width="145"><uc1:menu id="Menu1"
runat="server"></uc1:menu><img height="1" src="images/1x1.gif" width="145">
</td>
<td width="20"></td>
<td valign="top">
<table cellSpacing="0" cellPadding="0" width="100%" border="0"
ID="Table1">
<TBODY>
<tr>
<td vAlign="middle" width="100%" class="PageHeading">
<!-- Page Title Goes Here-->
<hr>
<br>
</td>
</tr>
<tr>
<td>
<!-- Page Content Goes Here-->
</td>
</tr>
</table>
</td>
</tr>
</TBODY></table>
</body>
</HTML>

I have not found a technique that allows me to load the above HTML, then
load the page content, and then continue building the page HTML. Any
suggestions?
 
I would not recommend tables for layout, look at CCS (yes, it does loads
more than colours and fonts)

but todo this you could put your template in a server control and make it
'contain' the real webpage, I have done this with the app I am working on
now, I have a DIV in the middle and I add controls to this DIV.

Steve
 
OK, I have done this and to get EVERY bit of this to work like you want, it may take some work.

I have a PageTemplate class which inherits from Page, and then my pages inherit from it.
What it does is
Creates a Form control,
Removes ALL the controls from the page's Controls collection, strips out certain values and holds them temporarily,
Creates a Table control
Loads UserControls (which are specified through properties at design time) for a banner, menu, and left column into cells of the Table,
Takes all the held Controls and adds them to the Table cell that displays the content of the page,
Adds the cells (banner, menu, left column, content) to the Table,
Adds the Table to the Form,
then RENDERS IT ALL!!! :)

'Build my new controls from scratch

'(FORM)
'
' Template Table
' |---------------------|
' | Banner |
' |---------------------|
' | Menu |
' \---------------------\ |-----|-------------|
' \ \ | Le | Content |
' \ \ | ft | |
' \ Content subtable --\----> | | (Control |
' \ \ | Col | Collection) |
' \ \ | umn | |
' \---------------------\ |-----|-------------|





I remove all the controls from the existing page, then add them to my class' form because if I just added the page's content to my table and rendered the table, the form would only contain what whas in the page, making any active content in the template pieces impossible.

Does this sound like something you're trying to do? If so, reply back to this thread.
 
I'm attaching the page template I use. It allows me to design the page,
although you do need to manually delete the header, body and html tags (i.e.
you will only have the content of the page in the HTML view).

I have header and footer custom controls that emit the HTML to define the
header and footer of the page. The ones I use read in a file from disk that
contains the HTML fragments which allows me to easily modify the look of the
page without recompiling.

I will also echo the comment that CSS is a far better choice for layout than
tables. Table should be reserved for presenting tabular data, not
controlling presentation. See www.alistapart.com or http://tinyurl.com/vzf5
(link to Amazon.com).

Colin
 
I guess they took a look at the proliferation of articles on creating page
templates and decided they had better do something about it.

That article has a good set of links at the end to other articles on page
templates. I used information from almost all of them to come up with my
solution.

Colin
 
Back
Top