Correct way to add formatted HTML?

  • Thread starter Thread starter Ayende Rahien
  • Start date Start date
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.
 
Back
Top