Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Generating live HTML server side controls from .Net classes

Reply
Thread Tools

Generating live HTML server side controls from .Net classes

 
 
=?Utf-8?B?Q2hhcmxlc0E=?=
Guest
Posts: n/a
 
      03-10-2006
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

 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      03-10-2006
> 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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2hhcmxlc0E=?=
Guest
Posts: n/a
 
      03-10-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
client-side controls and server-side code Jake ASP .Net 2 08-17-2005 01:12 AM
Confused about Server side/ client side and which controls to use msnews ASP .Net 0 05-26-2005 11:01 PM
Generating side-by-side differences in HTML Dan Gass Python 0 09-03-2004 01:22 PM
client side vs server side events for controls Mong ASP .Net 5 05-07-2004 01:20 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM



Advertisments