Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
What is "RenderControl" method? How it can be used in C#? Please explain with an eg.

the RenderControl throws an error "does not contain a definition for 'RenderControl' and no extension method RenderControl accepting a first argument of type Publish_View.Publish_HTML could be found (are you missing a using directive or an assembly reference?)"

My Code is:

C#
public string getstructure()
        {
            System.IO.StringWriter StringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter HTMLWriter = new System.Web.UI.HtmlTextWriter(StringWriter);
            this.RenderControl(HTMLWriter);
            string thisstructure = StringWriter.ToString();
            HTMLWriter.Close();
            StringWriter.Close();
            HTMLWriter = null;
            StringWriter = null;
            return thisstructure;
        }
Posted
Updated 22-Dec-11 2:01am
v5

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


Below is RenderControl method implementation, which receives any control and returns its HTML string representation.

C#
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();
}
 
Share this answer
 
Comments
maajanes 22-Dec-11 23:43pm    
Its throwing errors:

1.The best overloaded method match for 'Publish_View.Publish_HTML.RenderControl(System.Web.UI.Control)' has some invalid arguments

2.cannot convert from 'System.Web.UI.HtmlTextWriter' to 'System.Web.UI.Control'

My code is:public string getstructure() {

System.IO.StringWriter StringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter HTMLWriter = new System.Web.UI.HtmlTextWriter(StringWriter);

this.RenderControl(HTMLWriter);

string thisstructure = StringWriter.ToString();

HTMLWriter.Close(); StringWriter.Close();

HTMLWriter = null; StringWriter = null;

return thisstructure; }
Please give the list of namespaces which you are using on this page.
I will compare these with my page bcoz it is running on my page.
 
Share this answer
 
Comments
maajanes 22-Dec-11 7:42am    
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Configuration;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900