Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2009-05-06
1
745 Views
Last Modified: 2012-05-06
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
Comment
Question by:josephdaviskcrm
1 Comment
 
LVL 12

Accepted Solution

by:
wht1986 earned 500 total points
ID: 24317579
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
c.RenderControl(tw);
string s = sw.ToString();
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question