Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Generating HTML code in the code-behind

Reply
Thread Tools

Generating HTML code in the code-behind

 
 
lisa@starways.net
Guest
Posts: n/a
 
      08-25-2005
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

 
Reply With Quote
 
 
 
 
Anton
Guest
Posts: n/a
 
      09-25-2005
intrader wrote:
> On Thu, 25 Aug 2005 13:25:49 -0700, lisa wrote:
>
>
>>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

>
> 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.
>
>


Lastly OuterHTML is not available on Firefox. It's a Web browser.
Just so you know.
 
Reply With Quote
 
 
 
 
jjrdk
Guest
Posts: n/a
 
      09-25-2005
I'm not quite sure what you mean by this. Of course you can render
javascript in a control and have it refer to the HTML that the control
renders. There are certain pitfalls that you should observe regarding the
way the control's ID may be generated on complex pages.

The easiest way to insert javascript is to use the
"regiserclientscriptblock" or "registerstartupscript" in the control.

Anyway it would be easier to understand if you gave some more details about
what you were trying to do.

jjrdk

<> wrote in message
news: oups.com...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically generating html vs using html scaffolding? Faisal Vali Javascript 10 06-21-2008 04:31 PM
Generating HTML code in the code-behind lisa@starways.net ASP .Net Building Controls 2 09-25-2005 05:24 PM
Html code cleaner - Powerful HTML Code Compression Tool heren ASP .Net 1 09-14-2005 12:39 PM
Generating HTML code =?Utf-8?B?Y25pY2ts?= ASP .Net 2 03-22-2005 02:24 PM
HTML code warnings in asp.net html code view Craig Kenisston ASP .Net 3 10-07-2004 04:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57