Templating technique

  • Thread starter Patrick Kristiansen
  • Start date
P

Patrick Kristiansen

Hi group!

I've been using the templating technique where you create an inherited class
of Page, and during it's Render method write the template HTML before
calling base.Render(). (See http://tinyurl.com/33lbz).

But what if I have a page, where I would like to be able to generate a
dynamic left aligned menu? I would like to include the HTML for this menu in
the same .aspx file as I have my content for the page. Is this possible in
anyway?

Hope you understand what I mean.

Thanks in advance,
Patrick
 
N

Natty Gur

Hi,

You can use System.Web.HttpContext.Current.Handler to get a reference to
the calling page from your base class. then find the HTMLForm control
and add your HTML to the Form :

// MyPage class implementation
protected override void OnInit(EventArgs e)
{
System.Web.UI.Page CallPage =
(System.Web.UI.Page)System.Web.HttpContext.Current.Handler;

foreach (Control o in CallPage.Controls)
{
if (o is System.Web.UI.HtmlControls.HtmlForm )
{
System.Web.UI.HtmlControls.HtmlGenericControl oGenCont = new
System.Web.UI.HtmlControls.HtmlGenericControl();
oGenCont.InnerHtml = "<B>NATTY</B>";
o.Controls.Add(oGenCont);
}
}
}

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top