Templating technique

  • Thread starter Thread starter Patrick Kristiansen
  • Start date 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
 
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
 
Back
Top