Generating live HTML server side controls from .Net classes

G

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
 
H

Hans Kesting

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
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top