Amit's Blog

Sharing Thoughts and Learning

  Home  |   Contact  |   Syndication    |   Login
  43 Posts | 1 Stories | 153 Comments | 14 Trackbacks

News

About Me?
Read it in
Blog Statistics
Proud Member of

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
posted on Saturday, June 23, 2007 4:23 PM