473,748 Members | 8,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.LoadContro l) 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

{

HtmlContainerCo ntrol Body

{

get;

}

HtmlContainerCo ntrol 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(I PageTemplate 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.as cx - 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.W eb.UI.IPageTemp late" %>

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

public System.Web.UI.H tmlControls.Htm lContainerContr ol Body

{

get

{

return body;

}

}

public System.Web.UI.C ontrol Content

{

get

{

return content;

}

}

public System.Web.UI.H tmlControls.Htm lContainerContr ol 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:PlaceHolde r 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.W eb.UI.IPageCont ent" %>

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

void HB.Web.UI.IPage Content.AddToTe mplate(HB.Web.U I.IPageTemplate template)

{

template.Conten t.Controls.Add( this);

}

</script>

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

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

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

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(objec t sender, EventArgs e)

{

//load template

Control template = LoadControl("Te mplateTest.ascx ");

//load the content and invoke AddToTemplate

Control content = LoadControl("Te st.ascx");

((IPageContent) content).AddToT emplate((IPageT emplate) template);

//add the template to the page.

Controls.Add(te mplate);

}

</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="__aspnetF orm" method="post" action="Test.as px"
id="__aspnetFor m">

<input type="hidden" name="__VIEWSTA TE"
value="dDw1Mzgx Ozs+ON1TyCLuD5s ISHo9HTqB06VGFh 4=" />

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 1776
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******** ********@TK2MSF TNGP11.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.LoadContro l) 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

{

HtmlContainerCo ntrol Body

{

get;

}

HtmlContainerCo ntrol 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(I PageTemplate 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.as cx - 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.W eb.UI.IPageTemp late" %>

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

public System.Web.UI.H tmlControls.Htm lContainerContr ol Body

{

get

{

return body;

}

}

public System.Web.UI.C ontrol Content

{

get

{

return content;

}

}

public System.Web.UI.H tmlControls.Htm lContainerContr ol 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:PlaceHolde r 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.W eb.UI.IPageCont ent" %>

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

void HB.Web.UI.IPage Content.AddToTe mplate(HB.Web.U I.IPageTemplate template)
{

template.Conten t.Controls.Add( this);

}

</script>

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

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

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(objec t sender, EventArgs e)

{

//load template

Control template = LoadControl("Te mplateTest.ascx ");

//load the content and invoke AddToTemplate

Control content = LoadControl("Te st.ascx");

((IPageContent) content).AddToT emplate((IPageT emplate) template);

//add the template to the page.

Controls.Add(te mplate);

}

</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="__aspnetF orm" method="post" action="Test.as px"
id="__aspnetFor m">

<input type="hidden" name="__VIEWSTA TE"
value="dDw1Mzgx Ozs+ON1TyCLuD5s ISHo9HTqB06VGFh 4=" />

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
6576
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? Here's what I'm generally trying to achieve: I'm building (trying to anyway) a serialization library. Here's my design:
0
357
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 following reasons: 1) Render blocks are not allowed inside a templated control. 2) I want the inner controls scoped at the parent aspx (or ascx), not at the template naming container. This type of control would be ideal for website headers and...
4
2933
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 of these fields are text based, and I really want to have them appear as a label rather than a text box that is read only. I really want different behaviour for creation, edit and view. I guess I need to write a templated data-bound control.
2
2920
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 for a website in IIS 5.0 or later. interesting thing is i don't know how to do it. i tried to find out namespace or library in VS.NET 2.0, if there is any, but i failed to found one.
4
4824
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 know if there are open-source CMS tools or MLM tools available that helps me to customize or even upgrade to the kind of system I'd like to have. I'd like to know how should I start building one from scratch- just the logics or algorithms that I...
31
3199
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 some of the most powerful programming tools I have found. Often times as my program grows so do my objects. Often times I look back and see that my objects could be broken down int several smaller more re-usable module pieces of code. Is it a...
10
2224
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 argument list argument types are: (obj *) : defclass::base(p) ^ detected during instantiation of
7
1729
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, short Trank, bool Tcont> TopTen<Tnum,Trank,Tcont>::TopTen( const TopTen<Tnum,Trank,Tcont& tten );
2
2935
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
8984
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9312
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.