473,387 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating templated websites in asp.net -- i need feedback

The way the system works is, you create a user control (ascx) that will be a
template and must implement the interface IPageTemplate. You then create one
or more user controls (ascx) that implement the IPageContent interface. A
page (aspx) must then be created that loads (using Page.LoadControl) the
page template, and the page content. The page content adds itself to the
page template. The page template is then added to the aspx's control
collection. [Remember , Page and UserControl, derive from Control]. The
known drawbacks to this system are, it will double the file count since each
templated page must have an ascx and an aspx. Since the content of the
rendered page is stored in ascx files, the ids of server controls will be
changed at render-time.

My implementation of templated websites is based on the idea that, one wants
to develop a website where all pages have a consistent layout content [e.x.:
the same header, footer, and maybe a navigation bar on the left hand side]
with unique/dynamic content for each page. If you separate the two, every
page has a 'template' and '[dynamic] content' and I present to you, the two
interfaces, IPageTemplate and IPageContent.

public interface IPageTemplate

{

HtmlContainerControl Body

{

get;

}

HtmlContainerControl Head

{

get;

}

Control Content

{

get;

}

}

The IPageTemplate interface was created on the idea/assumption that every
template should have at least 3 HTML sections. A HTML body section, a HTML
head section, and a section where the dynamic content should be placed. You
may even encounter cases where the Content property returns the same
reference as the Body property. Anything more (such as a Title property, a
'NavigationBar' property, etc) can be specified in another interface or
class that implements IPageTemplate. The definition of the IPageContent is
as followed:

public interface IPageContent

{

void AddToTemplate(IPageTemplate pageTemplate);

}

It has only one method 'AddToTemplate'. The idea behind this is the method
is to be called to let the content 'add itself to a page template'.

To a show a simple example of the following in action, I present the three
files.

TemplateTest.ascx - This is my "master" page. It defines the template I
would like to use. I define a simple layout where I want every page to start
with "TEMPLATE EPILOGUE" and end with "TEMPLATE PROLOGUE".

I implement the IPageTemplate interface.

----------------------------------------------------------------------------

<%@ Control%>

<%@ Implements interface="HB.Web.UI.IPageTemplate" %>

<script language="C#" runat="server">

public System.Web.UI.HtmlControls.HtmlContainerControl Body

{

get

{

return body;

}

}

public System.Web.UI.Control Content

{

get

{

return content;

}

}

public System.Web.UI.HtmlControls.HtmlContainerControl Head

{

get

{

return head;

}

}

</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head runat="server" id="head">

</head>

<body runat="server" id="body">

<form runat="server" method="post">

TEMPLAE EPILOGUE<br>

<asp:PlaceHolder ID="content"
Runat="server"></asp:PlaceHolder>

TEMPLAE PROLOGUE<br>

</form>

</body>

</html>

----------------------------------------------------------------------------

Test.ascx - Here I define a content section that outputs the date and time.

----------------------------------------------------------------------------

<%@ Control%>

<%@ Implements interface="HB.Web.UI.IPageContent" %>

<script language="C#" runat="server">

void HB.Web.UI.IPageContent.AddToTemplate(HB.Web.UI.IPa geTemplate template)

{

template.Content.Controls.Add(this);

}

</script>

I AM DYNAMIC CONTENT <%=DateTime.Now.ToString()%><br>

----------------------------------------------------------------------------

Test.aspx - Here I create a page that loads it's respective content
(Test.ascx) and the template I want to use (TemplateTest.ascx).

I then call AddToTemplate on the content control to make it add itself to
the template. I then add the template to the page's controls.

----------------------------------------------------------------------------

<%@ Page%>

<script language="C#" runat="server">

public void Page_Init(object sender, EventArgs e)

{

//load template

Control template = LoadControl("TemplateTest.ascx");

//load the content and invoke AddToTemplate

Control content = LoadControl("Test.ascx");

((IPageContent)content).AddToTemplate((IPageTempla te) template);

//add the template to the page.

Controls.Add(template);

}

</script>

----------------------------------------------------------------------------

And the redered html is

----------------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head id="_ctl0_head">

</head>

<body id="_ctl0_body">

<form name="__aspnetForm" method="post" action="Test.aspx"
id="__aspnetForm">

<input type="hidden" name="__VIEWSTATE"
value="dDw1MzgxOzs+ON1TyCLuD5sISHo9HTqB06VGFh4=" />

TEMPLAE EPILOGUE<br>

I AM DYNAMIC CONTENT 11/25/2004 12:58:43 PM<br>

TEMPLAE PROLOGUE<br>

</form>

</body>

</html>

----------------------------------------------------------------------------
Nov 18 '05 #1
1 1744
Hasani,
You are on the right track. Check out some other implementations of
master pages.
http://authors.aspalliance.com/PaulW...rticles/?id=14
http://www.metabuilders.com/Tools/MasterPages.aspx

Best regards,
Jeffrey Palermo

"Hasani (remove nospam)" <ha****@n0sp4m.estorecorp.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The way the system works is, you create a user control (ascx) that will be a template and must implement the interface IPageTemplate. You then create one or more user controls (ascx) that implement the IPageContent interface. A
page (aspx) must then be created that loads (using Page.LoadControl) the
page template, and the page content. The page content adds itself to the
page template. The page template is then added to the aspx's control
collection. [Remember , Page and UserControl, derive from Control]. The
known drawbacks to this system are, it will double the file count since each templated page must have an ascx and an aspx. Since the content of the
rendered page is stored in ascx files, the ids of server controls will be
changed at render-time.

My implementation of templated websites is based on the idea that, one wants to develop a website where all pages have a consistent layout content [e.x.: the same header, footer, and maybe a navigation bar on the left hand side]
with unique/dynamic content for each page. If you separate the two, every
page has a 'template' and '[dynamic] content' and I present to you, the two interfaces, IPageTemplate and IPageContent.

public interface IPageTemplate

{

HtmlContainerControl Body

{

get;

}

HtmlContainerControl Head

{

get;

}

Control Content

{

get;

}

}

The IPageTemplate interface was created on the idea/assumption that every
template should have at least 3 HTML sections. A HTML body section, a HTML
head section, and a section where the dynamic content should be placed. You may even encounter cases where the Content property returns the same
reference as the Body property. Anything more (such as a Title property, a
'NavigationBar' property, etc) can be specified in another interface or
class that implements IPageTemplate. The definition of the IPageContent is
as followed:

public interface IPageContent

{

void AddToTemplate(IPageTemplate pageTemplate);

}

It has only one method 'AddToTemplate'. The idea behind this is the method
is to be called to let the content 'add itself to a page template'.

To a show a simple example of the following in action, I present the three
files.

TemplateTest.ascx - This is my "master" page. It defines the template I
would like to use. I define a simple layout where I want every page to start with "TEMPLATE EPILOGUE" and end with "TEMPLATE PROLOGUE".

I implement the IPageTemplate interface.

-------------------------------------------------------------------------- --
<%@ Control%>

<%@ Implements interface="HB.Web.UI.IPageTemplate" %>

<script language="C#" runat="server">

public System.Web.UI.HtmlControls.HtmlContainerControl Body

{

get

{

return body;

}

}

public System.Web.UI.Control Content

{

get

{

return content;

}

}

public System.Web.UI.HtmlControls.HtmlContainerControl Head

{

get

{

return head;

}

}

</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head runat="server" id="head">

</head>

<body runat="server" id="body">

<form runat="server" method="post">

TEMPLAE EPILOGUE<br>

<asp:PlaceHolder ID="content"
Runat="server"></asp:PlaceHolder>

TEMPLAE PROLOGUE<br>

</form>

</body>

</html>

-------------------------------------------------------------------------- --
Test.ascx - Here I define a content section that outputs the date and time.
-------------------------------------------------------------------------- --
<%@ Control%>

<%@ Implements interface="HB.Web.UI.IPageContent" %>

<script language="C#" runat="server">

void HB.Web.UI.IPageContent.AddToTemplate(HB.Web.UI.IPa geTemplate template)
{

template.Content.Controls.Add(this);

}

</script>

I AM DYNAMIC CONTENT <%=DateTime.Now.ToString()%><br>

-------------------------------------------------------------------------- --
Test.aspx - Here I create a page that loads it's respective content
(Test.ascx) and the template I want to use (TemplateTest.ascx).

I then call AddToTemplate on the content control to make it add itself to
the template. I then add the template to the page's controls.

-------------------------------------------------------------------------- --
<%@ Page%>

<script language="C#" runat="server">

public void Page_Init(object sender, EventArgs e)

{

//load template

Control template = LoadControl("TemplateTest.ascx");

//load the content and invoke AddToTemplate

Control content = LoadControl("Test.ascx");

((IPageContent)content).AddToTemplate((IPageTempla te) template);

//add the template to the page.

Controls.Add(template);

}

</script>

-------------------------------------------------------------------------- --
And the redered html is

-------------------------------------------------------------------------- --
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head id="_ctl0_head">

</head>

<body id="_ctl0_body">

<form name="__aspnetForm" method="post" action="Test.aspx"
id="__aspnetForm">

<input type="hidden" name="__VIEWSTATE"
value="dDw1MzgxOzs+ON1TyCLuD5sISHo9HTqB06VGFh4=" />

TEMPLAE EPILOGUE<br>

I AM DYNAMIC CONTENT 11/25/2004 12:58:43 PM<br>

TEMPLAE PROLOGUE<br>

</form>

</body>

</html>

-------------------------------------------------------------------------- --

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
0
by: John Crowley | last post by:
I keep running into this over and over again... I want a block server control that renders a header and footer, and child controls in between. But I don't want a templated control, for the...
4
by: Martin | last post by:
I want to build a data entry form for creating and updating info on something. When I'm first creating an item all the fields need to be editable. There after some fields become readonly. Most...
2
by: lucky | last post by:
Hello Guys, after long long time. i'm back again with some questions. right now i'm developing a code that fetch the list of websites from IIS 5.0 or later and also cretes the Virtual Directory...
4
by: crescent_au | last post by:
Hi all, I'm doing some research online on creating php-based multi-level marketing (MLM) system. It seems like a complicated system to build as I need to create one from scratch. I'd like to...
31
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are...
10
by: Keith Halligan | last post by:
I'm switching from the HP-UX compiler aCC 5.55 to aCC 6.13 and I get the following error: "templateptr.h", line 20: error #2289: no instance of constructor "defclass::base::base" matches the...
7
by: Claudius | last post by:
Hello, in my class TopTen I need to define three constructors while only the last one, the most general in terms of templates, should be sufficient in my opinion: template <typename Tnum,...
2
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.