Solved

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

Posted on 2009-05-06
1
742 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Editing XSL files, 2 43
Auto refresh part of an MVC5 View 7 60
Angular JS Route 3 54
ASP.net Run 3 sliders vertically as opposed to horizontally 9 20
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now