You are here:   Home
Register  |  Login
 RSS Subscribe
Minimize
 Blog Calendar
Minimize
 Share This
Minimize
 Captured Technology - Blog
Minimize
May 15

Written by: Steve Patterson
5/15/2009 4:19 PM  RssIcon

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)

Tags:
Categories:

4 comment(s) so far...


Gravatar

Re: Building HTML in the Page_Init Event

Programming is my weakness. I find it hard to understand this.

By Sacramento dating on   5/21/2009 8:25 PM
Gravatar

Re: Building HTML in the Page_Init Event

i know HTML but i don knw CSS. I m keen to learn CSS. Though i know my mind is too short to learn CSS.. :)

Thanks
Car Stereo

By maria jennifer on   5/26/2009 3:12 AM
Gravatar

Re: Building HTML in the Page_Init Event

I'm very grateful to you for providing the code. I'm searching for this code for a long time.

By Web design sunshine coast on   8/12/2009 8:00 AM
Gravatar

Re: Building HTML in the Page_Init Event

where did u get this code?

By who invented the computer on   5/25/2010 11:46 PM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
 Blog Directory
Minimize
 Mobile Version
Minimize
Add CapturedTech - Technology Mippin widget
 Translate
Minimize
 Sponsors
Minimize
Great deals on Back to School items at OfficeMax

u comment, i follow