newbie: asp page templatess

S

suzy

hi i am quite new to .net and am trying to implement page templates but i
just cant seem to get it to work, and i dont quite follow the examples on
the net.

all i want to do is create a template where i have a header (user control),
left column, and footer on every page. the remainder of the page will
change per page.

can anyone please help? i think i know that i have to create a template.cs
file which inherits from the page object. and then my aspx page inherits
from the template.cs object, but the examples seem to confuse me after that.
 
M

Marcin

Hi,

Yes you can inherit from Page class. In your template override
OnInit() method and load your header and footer controls.

example:
protected override void OnInit(EvantArgs args)
{
this.Controls.AddAt(0, LoadControl("path to header.ascx " );
base.OnInit(e);
this.Controls.Add(LoadControl("path to footer.ascx"));
}

Now if any page will inherit from template class it will be wrapped in
header and footer.

Regards
Marcin
 
S

suzy

it doesn't work for me.

the header and footer appear, but not the main content.

how should i be adding my main content to my main page? and where do the
html/body/title/etc tags go?

thanks

Marcin said:
Hi,

Yes you can inherit from Page class. In your template override
OnInit() method and load your header and footer controls.

example:
protected override void OnInit(EvantArgs args)
{
this.Controls.AddAt(0, LoadControl("path to header.ascx " );
base.OnInit(e);
this.Controls.Add(LoadControl("path to footer.ascx"));
}

Now if any page will inherit from template class it will be wrapped in
header and footer.

Regards
Marcin



"suzy" <[email protected]> wrote in message
that.
 
M

Marcin

It should work.

It will reneder the controls in the following sequence:
1. header.
2. your page content (that inherits from PageTemplate)
3. footer

All the tags should be placed in such a way that when the page is
rendered it will generate valid HTML code. For example:
<html> <head></head> and opening <body> tag could go to the header
control.
</body> and </html> could go to your footer. Your page content should
define only the "inner part" of the page (no <body>,<head> tags
etc..).

Good luck.

Marcin
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top