Generating HTML code in the code-behind

Discussion in 'ASP .Net Web Controls' started by lisa@starways.net, Aug 25, 2005.

  1. Guest

    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
    , Aug 25, 2005
    #1
    1. Advertising

  2. Anton Guest

    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. :p
    Just so you know. ;)
    Anton, Sep 25, 2005
    #2
    1. Advertising

  3. jjrdk Guest

    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:...
    > 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
    >
    jjrdk, Sep 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    554
    Alphonse Giambrone
    Jun 28, 2003
  2. Nevyn Twyll
    Replies:
    4
    Views:
    738
    Nevyn Twyll
    Mar 6, 2004
  3. =?Utf-8?B?bmV0Y29tbWFuZGVy?=

    Generating XML comment documents from ASP.NET C# code-behind

    =?Utf-8?B?bmV0Y29tbWFuZGVy?=, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    756
    Rick Strahl [MVP]
    Jan 25, 2006
  4. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    451
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  5. Generating HTML code in the code-behind

    , Aug 25, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    141
    jjrdk
    Sep 25, 2005
Loading...

Share This Page