CapturedTech.com

Captured Technology

Building HTML in the Page_Init Event

May 15 2009

Building HTML in the Page_Init Event

In relation to the CSS Rounded Corners that I wrote about recently, we needed to have the rounded corners rendered in the Page_Init event of a user control instead of being part of a markup page. Therefore I researched adding simple Html tags in code and found the HtmlControls.HtmlGenericControl method which creates generic Html controls, obviously. The CSS Rounded Corners Html code is a combination of bold tags mostly with some div tags and CSS classes to go along. Here is an example of the Html for the rounded corners in Asp.Net code behind.

        ' The Rounded Header 
        Dim objB1h As New HtmlControls.HtmlGenericControl("b")
        objB1h.Attributes.Add("class", "b1h")
        Dim objB2h As New HtmlControls.HtmlGenericControl("b")
        objB2h.Attributes.Add("class", "b2h")
        Dim objB3h As New HtmlControls.HtmlGenericControl("b")
        objB3h.Attributes.Add("class", "b3h")
        Dim objB4h As New HtmlControls.HtmlGenericControl("b")
        objB4h.Attributes.Add("class", "b4h")

        ' The Rounded Footer
        Dim objB1bh As New HtmlControls.HtmlGenericControl("b")
        objB1bh.Attributes.Add("class", "b1bh_gray")
        Dim objB2bh As New HtmlControls.HtmlGenericControl("b")
        objB2bh.Attributes.Add("class", "b2bh_gray")
        Dim objB3bh As New HtmlControls.HtmlGenericControl("b")
        objB3bh.Attributes.Add("class", "b3bh_gray")
        Dim objB4bh As New HtmlControls.HtmlGenericControl("b")
        objB4bh.Attributes.Add("class", "b4bh_gray")

        ' The Header Text
        Dim objBr As New HtmlControls.HtmlGenericControl("b")
        objBr.Attributes.Add("class", "br")
        Dim objDivHeadh As New HtmlControls.HtmlGenericControl("div")
        objDivHeadh.Attributes.Add("class", "headh")
        Dim objHeaderContainer As New MessageContainer
        HeaderTemplate.InstantiateIn(objHeaderContainer)
        objDivHeadh.Controls.Add(objHeaderContainer)

        ' The Content
        Dim objDivContenth As New HtmlControls.HtmlGenericControl("div")
        objDivContenth.Attributes.Add("class", "contenth_gray")
        Dim objBodyContainer As New MessageContainer
        BodyTemplate.InstantiateIn(objBodyContainer)
        objDivContenth.Controls.Add(objBodyContainer)

        Me.Controls.Clear()
        Me.Controls.Add(objB1h)
        Me.Controls.Add(objB2h)
        Me.Controls.Add(objB3h)
        Me.Controls.Add(objB4h)
        Me.Controls.Add(objDivHeadh)
        Me.Controls.Add(objBr)
        Me.Controls.Add(objDivContenth)
        Me.Controls.Add(objB4bh)
        Me.Controls.Add(objB3bh)
        Me.Controls.Add(objB2bh)
        Me.Controls.Add(objB1bh)

Blog Directory

Latest technology news.
 Patrick Stevens
 554  246480  11/15/2024

FaceBook

Translate