• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

ASP.NET - Render html of a conrol in the code behind

I'm dynamically building an html table in the code behind and need to render it into html so that I can use that also in the code behind.  I'm tyring to use the control.RenderControl() method but I'm having a hard time.

Below is what I've tried so far.

But the HtmlTextWriter must have a System.IO.TextWriter object passed to it.  When I try to create a System.IO.TextWriter object I get an error saying that I cannot create a new instance of a must inherit class.

What is the easiest way of doing what I'm trying to do here.
writer = New HtmlTextWriter()
tbl.RenderControl(writer)
Dim strTest As String = writer.ToString

Open in new window

0
josephdaviskcrm
Asked:
josephdaviskcrm
1 Solution
 
wht1986Commented:
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
c.RenderControl(tw);
string s = sw.ToString();
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now