Off-Page Rendering of Server Controls with events

Discussion in 'ASP .Net' started by Bob Jones, Feb 21, 2007.

  1. Bob Jones

    Bob Jones Guest

    Hey everyone. I have another problem. I have an aspx web page that
    contains an event. When the event is fired it creates an instance of a
    server control that contains an event of its own. I would like to be
    able to render the contents of the server control (HTML w/ event
    JavaScript code) and store it for later use.

    My problem lies when I call the MyControl.RenderControl method. It
    returns valid HTML but does not contain the event code since the
    control has not been added to any page object.

    Here is what I have tried:

    HtmlForm hForm = new System.Web.UI.HtmlControls.HtmlForm();
    hForm.Attributes.Add("runat", "server");
    hForm.Controls.Add(spWC);

    Page p = new Page();
    p.Controls.Add(hForm);
    p.RenderControl(hWriter); // <-- error here stating that no Response
    object available.

    I do understand that I am getting a "Response not available" error
    because there is no context associated with the newly created page
    object. Any ideas as to how I can achieve the results I am looking
    for?

    -David
    Bob Jones, Feb 21, 2007
    #1
    1. Advertising

  2. Bob Jones

    Bob Jones Guest

    On Feb 21, 9:15 am, "Bob Jones" <> wrote:
    > Hey everyone. I have another problem. I have an aspx web page that
    > contains an event. When the event is fired it creates an instance of a
    > server control that contains an event of its own. I would like to be
    > able to render the contents of the server control (HTML w/ event
    > JavaScript code) and store it for later use.
    >
    > My problem lies when I call the MyControl.RenderControl method. It
    > returns valid HTML but does not contain the event code since the
    > control has not been added to any page object.
    >
    > Here is what I have tried:
    >
    > HtmlForm hForm = new System.Web.UI.HtmlControls.HtmlForm();
    > hForm.Attributes.Add("runat", "server");
    > hForm.Controls.Add(spWC);
    >
    > Page p = new Page();
    > p.Controls.Add(hForm);
    > p.RenderControl(hWriter); // <-- error here stating that no Response
    > object available.
    >
    > I do understand that I am getting a "Response not available" error
    > because there is no context associated with the newly created page
    > object. Any ideas as to how I can achieve the results I am looking
    > for?
    >
    > -David


    sp, nobody on here has any idea on how to get this working? Or if it's
    even possible
    Bob Jones, Feb 22, 2007
    #2
    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. Peter Mount
    Replies:
    4
    Views:
    943
    Peter Mount
    Jan 31, 2006
  2. newbye
    Replies:
    0
    Views:
    580
    newbye
    Jul 6, 2006
  3. Matt Feinstein

    Off-screen rendering in PyOpenGL?

    Matt Feinstein, Aug 17, 2005, in forum: Python
    Replies:
    0
    Views:
    533
    Matt Feinstein
    Aug 17, 2005
  4. SevDer
    Replies:
    2
    Views:
    1,298
    Walter Wang [MSFT]
    Nov 13, 2007
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    355
    Chris
    Aug 30, 2005
Loading...

Share This Page