I am developing an ASP.NET web application at work, and I keep running into the same issue:
Sometimes I want to write HTML to the page from the code-behind. For example, I have a page, Editor.aspx, with output which varies depending on the value of a GET variable, "view." In other words, "Editor.aspx?view=apples" outputs different HTML than "Editor.aspx?view=oranges".
I currently output this HTML with StringBuilder. For example, if I wanted to create a list, I might use the following syntax:
myStringBuilder.AppendLine("<ul id=\"editor-menu\">");
myStringBuilder.AppendLine("<li>List Item 1</li>");
myStringBuilder.AppendLine("</ul>");
The problem is that I would rather use ASP.NET's List control for this purpose, because several lines of StringBuilder syntax hamper my code's readability. However, ASP.NET controls tend to output convoluted HTML, with unique ID's, inline styles, and the occasional block of inline JavaScript.
My question is, is there an ASP.NET control which merely represents a generic HTML tag? In other words, is there a control like the following example:
HTMLTagControl list = new HTMLTagControl("ul");
list.ID = "editor-menu";
HTMLTagControl listItem = new HTMLTagControl("li");
listItem.Text = "List Item 1";
list.AppendChild(listItem);
I know there are wrappers and the such, but instead of taming ASP.NET complexity, I would rather start with simplicity from the get-go.