473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Generating live HTML server side controls from .Net classes

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

Mar 10 '06 #1
2 2417
> 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
Mar 10 '06 #2
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
Mar 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
1
by: Matthew Louden | last post by:
Personally, I am totally confused with the following control terms and usage and advantages of each one in ASP.NET web application. Here's what I know so far.. 1. HTML Client Control: understood...
7
by: Venus | last post by:
Hello, I am trying to generate a dynamic form at runtime and would like to do it using "<asp: ..." form elements as follows Build up the string that is placed somewhere in the HTML code the...
5
by: Brian Kitt | last post by:
I have a C# application that builds dynamic HTML and renders it. Because it is rendered in this way, the input controls are not server controls. I write the entire page, which has a variable...
4
by: SAI | last post by:
Both have "TextBox" element and "Runat server". I don't understand the difference. Please advise. Thanks.
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
1
by: Andy Fish | last post by:
Hi, In my aspx web application, I am generating a list of items in a menu down the left-hand side. Different items in the list may have different controls in, and this is data-driven at runtime....
2
by: Ellie | last post by:
I am just starting to develop in asp.net and I have somewhat of a familiarity with asp 3.0. I am comfortable with asp 3.0 for my server side processing and javascript for client side. I also like...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.