all groups > asp.net building controls > august 2005 >
You're in the

asp.net building controls

group:

Generating HTML code in the code-behind


Re: Generating HTML code in the code-behind intrader
8/25/2005 12:00:00 AM
asp.net building controls:
[quoted text, click to view]
I have not tried it, but you should be able to instantiate a control and
ask it to render to a stream.

What I have done requires overridint the Render method. There you should
create a StreamBuffer which you use to create an HTMLTextWriter, then you
tell the base to render itself, and voila, you have the HTML in the
StreamBuffer.

Generating HTML code in the code-behind lisa NO[at]SPAM starways.net
8/25/2005 1:25:49 PM
Can I do this?

I'm playing with AJAX, and it occurred to me that it'd be a lot easier
to make changes to a control on the server, grab the HTML that control
would now render, and return that to the client, where Javascript could
just use outerHTML to replace the whole control.

The obvious catch is generating that HTML.

I tried making an HTMLTextWriter and doing control.Render(writer), but
that gave me an error.

I don't want to override the Page's Render method, because I want to
make this fairly self-contained. Just stick it in a helper function in
a helper class, basically.

And after banging my head against it for a few days, I thought I'd ask
if anyone knows (a) how to do it, or (b) whether it can be done.

Thanks muchly,
Lisa
AddThis Social Bookmark Button