Argos
Phil's CRM Blog | All posts tagged 'custom-control'

Render Control into HTML String

by Phil Adams 6. July 2009 13:50

Occasionally there is a need to get string representation of ASP.NET control in other words - render it into string instead of letting it be rendered on the page. The following method renders a control into its HTML string.
Namespaces used:

using System.Text;
using System.IO;
using System.Web.UI;


public string RenderControl(Control ctrl) 
{
    StringBuilder sb = new StringBuilder();
    StringWriter tw = new StringWriter(sb);
    HtmlTextWriter hw = new HtmlTextWriter(tw);

    ctrl.RenderControl(hw);
    return sb.ToString();
}

Tags: ,

Custom Controls | ASP.Net

About Phil

Phil has been working with CRM since the BETA of CRM v1.0 and has seen a lot of the problems arising from installation, maintenance and Development.

Phil specializes in the ISV area of CRM; Creating Add-Ons and Plugins for various clients.

Phil currently works as a Microsoft Dynamics CRM Consultant and Developer for Cambridge Online Systems Ltd In the UK.

Phil also has several Microsoft Certifications in .NET and CRM