guyS's WebLog

IShare, My DotNet Fingerprint

Control to string

Shared by by Pronet components. 
I like its simplicity but yet the power it can gives developers.
I prefer to attached it to the post.
using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;

public class Render
{
	public static string RenderControl(System.Web.UI.Control control) 
	{
		StringBuilder result = new StringBuilder(1024);
		control.RenderControl(new HtmlTextWriter(new StringWriter(result)));
		return result.ToString();
	}
	public static string RenderControl(System.Web.UI.TemplateControl control) 
	{
		StringBuilder result = new StringBuilder(1024);
		control.RenderControl(new HtmlTextWriter(new StringWriter(result)));
		return result.ToString();
	}
	public static string RenderPage(string pageLocation)
	{
		System.Web.HttpContext context = System.Web.HttpContext.Current;
		StringBuilder result = new StringBuilder(1024);
		context.Server.Execute(pageLocation, new HtmlTextWriter(new StringWriter(result)));
		return result.ToString();
	}
}
Posted: May 30 2004, 12:23 AM by guyS |
Filed under: ,

Comments

No Comments