Get HTML of a control through a static method

jaycob

New Member
I am trying the following:\[code\]public partial class PopUps : System.Web.UI.Page { public string GetContentFromPlaceHolder(string strContentId) { HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter()); plcPlaceHolderToGet.RenderControl(writer); string strHtml = writer.InnerWriter.ToString(); return strHtml; } public static string GetContent() { PopUps puToUse = new PopUps(); string strHtml = puToUse.GetContentFromPlaceHolder(); return strHtml; }}\[/code\]However, when I run the static method \[code\]GetContent\[/code\] from another page I get this error:\[quote\] object reference not set to an instance of an object \[/quote\]on the line \[code\]plcPlaceHolderToGet.RenderControl(writer);\[/code\]The ID of the control is correct, it just seems like I need to run some kind of instantiation of the controls on the Page before I can get the HTML of one of the controls. What am I missing? The design view of the page looks like this\[code\]<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PopUps.aspx.cs" Inherits="PopUps" %><asp:placeHolder runat="server" id="plcPlaceHolderToGet"> <div> Some more HTML... </div></asp:placeHolder><asp:placeHolder runat="server" id="plcAnotherPlaceHolder"> <div> Some more HTML... </div></asp:placeHolder>\[/code\]I am trying to do this to have one place to hold all my HTML. HTML, that sometimes needs to be fetched from other C# code and sometimes through an AJAX call.
 
Top