Style to html

  • Thread starter Thread starter Jeremy Chapman
  • Start date Start date
J

Jeremy Chapman

I have a System.UI.Web.WebControls.Style object populated and I want to get
the html that it would generate. For example a label would generate <span
class="test">text</span> the class="test" comes from the Style object. How
can I programatically retrieve that html from the Style object?
 
Try this:

Style style = new Style();
// set properties on your style object

StringBuilder sb = new StringBuilder ( );
StringWriter sw = new StringWriter ( sb );
HtmlTextWriter tw = new HtmlTextWriter ( sw );

// now lets get the output of our Style Control
style.RenderControl ( tw );
 
Ooops...I left this out. You string builder should now have the HTML so
do a sb.ToString();
 

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

Back
Top