Generating live HTML server side controls from .Net classes

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2hhcmxlc0E=?=, Mar 10, 2006.

  1. Hi folks,
    I'm using ASP.net with Framework vs 1.1

    I'm inheriting from a custom rolled master page class that is just that a
    class that inherits from web.ui.page but it has no designer associated with
    it. I want to generate some HTML inside the class and then that stuff will be
    on every actual .aspx page that inherits from my master page class.

    I want this to be output on every page (amongst other stuff)

    <body id="intro">

    <ul id="nav">
    <li id="t-intro"><a href="Home.aspx">Home</a></li>
    <li id="t-about"><a href="Reports.aspx">Reports</a></li>
    <li id="t-news"><a href="Search.aspx.html">Search for a Record</a></li>
    <li id="t-sponsors"><a href="admin.aspx">Admin</a></li>
    </ul>

    </body>
    </html>

    This is a navigation tab that I learned from Dan Cederholm's excellent book.
    When it's CSSd it looks great


    so my question is. What .net classes can be used to create these controls in
    the masterPage class (litercontrol?, htmlControl?, htmlGenericControl)

    I've had a go with no success and what's thwarting me is that whilst it's
    easy to add say a <h1> heading this way, I have no idea how to add the outer
    <ul> tag and then nest some <li> children inside it and then close the outer
    tag...I can't seem to get any help from help


    in a nutshell.
    if I could get my master page class to generate some html inside it using
    proper server activatable html controls, then every page I use will inherit
    from my class masterPage and not web.ui.page and therefore it will have that
    nav bar on it. (I've adapted this example from something I read in Esposito
    magnum opus, so I'm not completely mad) the code has to be 'controls in
    memory' (rather than just html strings) because I want to change certain
    attributes of it on each page

    any idea what code to write to generate that collection of HTML controls?


    any answer would be greatly appreciated
    Regards and thanks in advance,
    CharlesA
    =?Utf-8?B?Q2hhcmxlc0E=?=, Mar 10, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?Q2hhcmxlc0E=?=

    Hans Kesting Guest

    > Hi folks,
    > I'm using ASP.net with Framework vs 1.1
    >
    > I'm inheriting from a custom rolled master page class that is just that a
    > class that inherits from web.ui.page but it has no designer associated with
    > it. I want to generate some HTML inside the class and then that stuff will be
    > on every actual .aspx page that inherits from my master page class.
    >
    > I want this to be output on every page (amongst other stuff)
    >
    > <body id="intro">
    >
    > <ul id="nav">
    > <li id="t-intro"><a href="Home.aspx">Home</a></li>
    > <li id="t-about"><a href="Reports.aspx">Reports</a></li>
    > <li id="t-news"><a href="Search.aspx.html">Search for a Record</a></li>
    > <li id="t-sponsors"><a href="admin.aspx">Admin</a></li>
    > </ul>
    >
    > </body>
    > </html>
    >
    > This is a navigation tab that I learned from Dan Cederholm's excellent book.
    > When it's CSSd it looks great
    >
    >
    > so my question is. What .net classes can be used to create these controls in
    > the masterPage class (litercontrol?, htmlControl?, htmlGenericControl)
    >
    > I've had a go with no success and what's thwarting me is that whilst it's
    > easy to add say a <h1> heading this way, I have no idea how to add the outer
    > <ul> tag and then nest some <li> children inside it and then close the outer
    > tag...I can't seem to get any help from help
    >
    >
    > in a nutshell.
    > if I could get my master page class to generate some html inside it using
    > proper server activatable html controls, then every page I use will inherit
    > from my class masterPage and not web.ui.page and therefore it will have that
    > nav bar on it. (I've adapted this example from something I read in Esposito
    > magnum opus, so I'm not completely mad) the code has to be 'controls in
    > memory' (rather than just html strings) because I want to change certain
    > attributes of it on each page
    >
    > any idea what code to write to generate that collection of HTML controls?
    >
    >
    > any answer would be greatly appreciated
    > Regards and thanks in advance,
    > CharlesA


    You can use a HtmlGenericControl. It has a constructor that lets you
    specify a tag.

    HtmlGenericControl ul = new HtmlGenericControl("ul");
    ul.Attributes["id"] = "nav";
    HtmlGenericControl li = new HtmlGenericControl("li");
    li.Attributes["id"] = "t-intro";
    li.InnerHtml = "<a href='Home.aspx'>Home</a>";
    ul.Controls.Add(li);

    and so on ...


    Hans Kesting
    Hans Kesting, Mar 10, 2006
    #2
    1. Advertising

  3. A million thanks Hans

    you've saved my day

    I had some idea how to start an <ul> tag, but none on how to close it or
    nest things inside it...
    accomplished in your post with
    ul.Controls.Add(li); I didn't know you could do that...
    also the whole thing works a treat...

    so thanks again
    Warm regards,
    CharlesA
    =?Utf-8?B?Q2hhcmxlc0E=?=, Mar 10, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,096
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. Mong
    Replies:
    5
    Views:
    4,718
    Kevin Spencer
    May 7, 2004
  3. msnews
    Replies:
    0
    Views:
    450
    msnews
    May 27, 2005
  4. Jake
    Replies:
    2
    Views:
    407
    Steve C. Orr [MVP, MCSD]
    Aug 17, 2005
  5. Dan Gass
    Replies:
    0
    Views:
    308
    Dan Gass
    Sep 3, 2004
Loading...

Share This Page