Correct way to add formatted HTML?

A

Ayende Rahien

I've an object that I want to display via HTML, what is the correct way to
do this? (Or the prefered way).
Currently I'm doing it this way:
private void AddStory(Story story)

{

System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append("<P><P><H2>").Append(story.Title).Append("</H2>");

sb.Append(story.Date).Append("<BR
/>").Append(story.Category).Append("</P><P>");

sb.Append(story.Teaser).Append("</P><P>Author: <A
HREF='mailto:").Append(story.Author.Email).Append("'>");

sb.Append(story.Author.Name).Append("</A>&nbsp;
(").Append(story.CommentsNumber()).Append(") comments");

sb.Append("&nbsp; <A
HREF='permalink.aspx?story=").Append(story.HiddenId).Append("'>Full
story</A></P>");

Content.Controls.Add(new LiteralControl(sb.ToString()));

}

Where Content is a placeholder on the page, and the content is being added
one after another.

This is ugly and error - prone.

How do I do it in a more efficant way?

I would love to use HTML/Web controls, but I've a problem in creating the
correct Html with them.

I would appritiate it if someone could post an example how to do the above
result in a better way.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top