Header Footer method for ASP Templates

travisowens

Centurion
Joined
Feb 11, 2004
Messages
108
Location
Rochester, NY
I am using the following code example I dug up to learn template based ASP.Net web apps but I don't see how I can add dynamic controls (iow creating a Table control and putting it into the page).

Here's the code for the header (testheader.ascx):
Code:
<div align="center">
<font Size="5"><b>Test Header</b></font>
</div>

Here's the code for the footer (testfooter.ascx):

Code:
<div align="center"><hr> 
<font Size="2"><i>Test Footer</i><br> Copyright 2002, All Rights Reserved</font> 
</div>
Now - here's the main page, where each user control is inserted:

Code:
<%@ Register TagPrefix="xprs" tagname="footer" src="Testfooter.ascx" %> 
<%@ Register TagPrefix="xprs" tagname="header" src="testheader.ascx" %> 
<html> 
<head> 
<meta name="GENERATOR" Content="ASP Express 2.0"> 
<title>Heading of Page Goes here</title> 
</head> 
<body> 
<xprs:header runat="server"/> 
<i><font Color="#0000FF">As you can see - the Header is on the top of this page. 
</font></i> <p> 

Again - two lines accomplish this, also.</font></i>
<xprs:footer runat="server"/> 
</body> 
</html>

Now when I try to do the following in my Page_Load event, no table appears in my page view in runtime, why not?
Code:
			Table menu = new Table();
			TableRow row = new TableRow();
			TableCell cell = new TableCell();
			cell.Text = "TestCell";
			row.Cells.Add(cell);
			menu.Rows.Add(row);
			
			Page.Controls.Add(menu);

			TextBox txtBox = new TextBox();
			Page.Controls.Add(txtBox);
 
Your code is not really Templating it's a UserControl.

To add a userControl at run-time do the following...

'At the top of your page inside your class....
Private myHeader As Control = LoadControl("UserControl/myHeader.ascx")

'Then in your init event ....
Me.Controls.Add(myHeader)
'Or you can add it to a Panel or something
 
Back
Top