Amit's Blog

Sharing Thoughts and Learning

  Home  |   Contact  |   Syndication    |   Login
  43 Posts | 0 Stories | 233 Comments | 14 Trackbacks

News

About Me?
Read it in
Blog Statistics
Proud Member of

Tag Cloud


Archives

Post Categories

Articles

Book Review

I Visit.

OpenSource Project(s)

While working on Ajax Data Controls Project, I need the generated HTML from an ITemplate. Here is the code that generates the html, some of you may find it useful.

   1:  StringBuilder output = new StringBuilder();
   2:  StringWriter sw = new StringWriter(output, CultureInfo.InvariantCulture);
   3:  HtmlTextWriter htw = new HtmlTextWriter(sw);
   4:   
   5:  Control control = new Control(); // Create a Fake control to act as a Container
   6:   
   7:  template.InstantiateIn(control); // This is the ITemplate
   8:  control.RenderControl(htw);//Dump the control in HTMLWriter
   9:   
  10:  htw.Close();
  11:   
  12:  string html = output.ToString(); // This is the generated HTML
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Saturday, June 23, 2007 4:23 PM

Feedback

# re: Generate HTML from an ITemplate 5/28/2008 12:12 AM David Basson
I think this is great but basically I would like to in code create a seperate html page with rendered code from the page used to generate it, any help would help

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: