Click here to Skip to main content
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 1:29am
Edited 22-Dec-11 3: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 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 22 Dec 2011
Copyright © CodeProject, 1999-2014
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