Click here to Skip to main content
11,718,589 members (86,740 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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:

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 22-Dec-11 0:29am
Edited 22-Dec-11 2:01am
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.

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();
}
  Permalink  
Comments
maajanes at 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; }
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
maajanes at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 750
1 F-ES Sitecore 250
2 OriginalGriff 230
3 Jochen Arndt 160
4 Maciej Los 130
0 Sergey Alexandrovich Kryukov 1,679
1 OriginalGriff 610
2 Maciej Los 529
3 Richard MacCutchan 460
4 F-ES Sitecore 455


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 22 Dec 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100