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

Creating a template in dot net

P: n/a
I am trying to create a template in dot net. All the articles I have
read on the net are rather confusing. I need a simple solution to
create a header and a footer on each page. Can someone point me into
the right direction.

I started off creating a file template.cs:

using System;
using System.Web;
using System.Web.UI;

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

then in the aspx page I did the following:
<%@ Page Language="C#" ContentType="text/html"
ResponseEncoding="iso-8859-1" Codebehind="template.cs" %>
This is the main content

does the template.cs need to be compiled?

Any thoughts?

Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If you use Src="template.cs" instead of Codebehind="template.cs", then
the cs file will compile when the page is requested.

You'll have a compiler error though, if the source you were showing
was the entire contents of the file. Methods have to exist inside of a
class declaration.

Have you tried the following article?
http://msdn.microsoft.com/library/de...rockASPNET.asp

--
Scott
http://www.OdeToCode.com/blogs/scott/

then in the aspx page I did the following:
<%@ Page Language="C#" ContentType="text/html"
ResponseEncoding="iso-8859-1" Codebehind="template.cs" %>
This is the main content

does the template.cs need to be compiled?

Any thoughts?


Nov 19 '05 #2

P: n/a
You can create a Visual Studio template using the information in the
following link, although it's not nearly as easy as it should be.
Here are the details:
http://www.sellsbrothers.com/writing...mtemplates.htm

In Visual Studio 2005 creating templates will be much easier. There will
also be Master Pages that will allow all your pages to inherit a common
structure.
http://www.c-sharpcorner.com/Code/20...asterPages.asp

Until then you might want to consider simply create a header user control
and a footer user control and dragging them onto each page and the top and
bottom respectively.
http://SteveOrr.net/faq/usercustom.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
<je*********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am trying to create a template in dot net. All the articles I have
read on the net are rather confusing. I need a simple solution to
create a header and a footer on each page. Can someone point me into
the right direction.

I started off creating a file template.cs:

using System;
using System.Web;
using System.Web.UI;

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

then in the aspx page I did the following:
<%@ Page Language="C#" ContentType="text/html"
ResponseEncoding="iso-8859-1" Codebehind="template.cs" %>
This is the main content

does the template.cs need to be compiled?

Any thoughts?

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.