Outside of benefiting from Adaptive Rendering for alternate devices, does it ever make sense to write all of this code:
writer.WriteBeginTag(\"t
At some point, you still need to pass this to a HtmlTextWriter in order to render to the client. I guess you would have a final writer.Write(sb.ToString()); in there in the second example. What you can do to reduce the lines of code is writing raw HTML, exactly the same way as in your second StringBuilder example, but using HtmlTextWriter.Write instead.
writer.Write("");
writer.Write(someTextVariable);
writer.Write("
");
Then using a StringBuilder seems unnecessary. And, HtmlTextWriter will, at least to some extent, make sure the generated HTML is compliant(although that is not true in the above case, when writing raw HTML).