[Mono-list] Capturing a Controls Rendered Html

Chris Day chrisd@monkey.biz
Fri, 17 Sep 2004 10:26:11 +1000


The code below should work, but the control may have to be added to a
page otherwise it may throw exceptions.

MemoryStream stream =3D new MemoryStream();
StreamWriter writer =3D new StreamWriter(stream, Encoding.Unicode);
HtmlTextWriter output =3D new HtmlTextWriter(writer);
yourcontrol.RenderControl(output);
output.Flush();
stream.Position =3D 0;
string outputStr =3D New StreamReader(stream, =
Encoding.Unicode).ReadToEnd;

> -----Original Message-----
> From: John BouAntoun [mailto:jbouantoun@rogen.com.au]=20
> Sent: Friday, 17 September 2004 9:11 AM
> To: Todd Berman; Matthew Metnetsky
> Cc: Mono - List
> Subject: RE: [Mono-list] Capturing a Controls Rendered Html
>=20
> Why not look into asp.net's data caching .
>=20
> Seems like a perfect scenario for use, "static most of the=20
> time, but changes ocasionally".
>=20
> JBA
>=20
> -----Original Message-----
> From: mono-list-admin@lists.ximian.com
> [mailto:mono-list-admin@lists.ximian.com] On Behalf Of Todd Berman
> Sent: Friday, 17 September 2004 8:20 AM
> To: Matthew Metnetsky
> Cc: Mono - List
> Subject: Re: [Mono-list] Capturing a Controls Rendered Html
>=20
>=20
> Maybe im missing something, but why not go to the page and=20
> view the source?
>=20
> Or do you want to automate this programmatically?
>=20
> --Todd
>=20
> On Thu, 2004-09-16 at 16:13 -0400, Matthew Metnetsky wrote:
> > I have a UserControl which contains all of my web pages header=20
> > information (menus etc).  The headers content is static=20
> 99.999% of the
>=20
> > time, so I would like to capture the rendered output of the control=20
> > and toss it into an HTML file for normal inclusion (and=20
> remove it when
>=20
> > the file needs updating.  But I'm getting lost following=20
> the API from=20
> > UserControl -> Control -> HtmlTextWriter -> TextWriter ->->->
> >=20
> > So I'm wondering if anyone has done anything similar=20
> before?  I don't=20
> > want the whole page, but rather just the text from one=20
> control down to
>=20
> > its children.  Any ideas or suggestions would be greatly=20
> appreciated.
> >=20
> > ~ Matthew
> >=20
> > _______________________________________________
> > Mono-list maillist  -  Mono-list@lists.ximian.com=20
> > http://lists.ximian.com/mailman/listinfo/mono-list
>=20
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com=20
> http://lists.ximian.com/mailman/listinfo/mono-list
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com=20
> http://lists.ximian.com/mailman/listinfo/mono-list
>=20
>=20