Groups | Blog | Home
all groups > asp.net > january 2004 >

asp.net : Templating technique


Patrick Kristiansen
1/24/2004 11:41:17 PM
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

Natty Gur
1/25/2004 10:19:35 PM
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


*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button