rendering a web control programmatically.

A

Alex

I'm trying to output a webcontrol in a non-standard way. What I want,
is the page to output xml with the html from the webcontrol in a CDATA
element of the XML document. My code looks something like this):

Response.ContentType = "text/xml";
Response.Write("<gateway><![CDATA[");
System.Web.UI.HtmlTextWriter htmlWriter = new
HtmlTextWriter(this.Response.Output);
System.Web.UI.Control control = LoadControl("MyControl.ascx");
control.RenderControl(htmlWriter);
Response.Write("]]></gateway>");

It works great for some controls but when a control is cached (<%@
OutputCache Duration="10" VaryByParam="None" %>) I get the following
exception:

Object reference not set to an instance of an object.

at System.Web.UI.BasePartialCachingControl.Render(HtmlTextWriter
output)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at home.GatewayContent.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\home\gatewaycontent.aspx.cs:line 49

Anyone have any ideas on what to do?

Thanks,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top