How to insert dynamically generated HTML into the <body> of an ASP.NET page?

Discussion in 'ASP .Net' started by Rick Spiewak, Jul 24, 2003.

  1. Rick Spiewak

    Rick Spiewak Guest

    I need to generate a "buy" button as part of an ASP.NET page - this consists
    of a small HTML form with hidden fields, conforming to the requirements of a
    merchant credit card processor. PayPal is similar.

    I'm succeeding in doing this by using Writer.Write to emit my HTML, at least
    as far as getting it to work.

    However, depending on where I put MyBase.Render(Writer), I get my HTML
    either before the header or after the end of the body of the HTML generated
    by ASP.NET. Oddly enough, both Netscape and IE seem to be happy to handle
    this. But, it looks ugly and is probably non-compliant.

    Anyone have any ideas as to how to split the difference and get my added
    HTML form into the <body>?

    TIA

    Rick Spiewak
     
    Rick Spiewak, Jul 24, 2003
    #1
    1. Advertising

  2. Off the top of my head, I wonder if adding a Literal server control to hold the
    content would serve your purpose? It is made to sit inside the existing
    server-side <form>. Maybe I've missed something?

    Ken

    "Rick Spiewak" <> wrote in message
    news:...
    I need to generate a "buy" button as part of an ASP.NET page - this consists
    of a small HTML form with hidden fields, conforming to the requirements of a
    merchant credit card processor. PayPal is similar.

    I'm succeeding in doing this by using Writer.Write to emit my HTML, at least
    as far as getting it to work.

    However, depending on where I put MyBase.Render(Writer), I get my HTML
    either before the header or after the end of the body of the HTML generated
    by ASP.NET. Oddly enough, both Netscape and IE seem to be happy to handle
    this. But, it looks ugly and is probably non-compliant.

    Anyone have any ideas as to how to split the difference and get my added
    HTML form into the <body>?

    TIA

    Rick Spiewak
     
    Ken Cox [Microsoft MVP], Jul 24, 2003
    #2
    1. Advertising

  3. Rick Spiewak

    bruce barker Guest

    a literal control won't work because you cannot nest forms in html. the
    easisest way is to write a function that renders the html and call from the
    page:

    <body>
    <% RenderBuyForm(); %>
    <form runat=server id=myform>
    ......
    </form>
    </body>




    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:en#...
    > Off the top of my head, I wonder if adding a Literal server control to

    hold the
    > content would serve your purpose? It is made to sit inside the existing
    > server-side <form>. Maybe I've missed something?
    >
    > Ken
    >
    > "Rick Spiewak" <> wrote in message
    > news:...
    > I need to generate a "buy" button as part of an ASP.NET page - this

    consists
    > of a small HTML form with hidden fields, conforming to the requirements of

    a
    > merchant credit card processor. PayPal is similar.
    >
    > I'm succeeding in doing this by using Writer.Write to emit my HTML, at

    least
    > as far as getting it to work.
    >
    > However, depending on where I put MyBase.Render(Writer), I get my HTML
    > either before the header or after the end of the body of the HTML

    generated
    > by ASP.NET. Oddly enough, both Netscape and IE seem to be happy to handle
    > this. But, it looks ugly and is probably non-compliant.
    >
    > Anyone have any ideas as to how to split the difference and get my added
    > HTML form into the <body>?
    >
    > TIA
    >
    > Rick Spiewak
    >
    >
    >
     
    bruce barker, Jul 25, 2003
    #3
  4. Rick Spiewak

    Rick Spiewak Guest

    Thanks for your suggestion. But, anything which creates another <form>
    tag at design time causes errors. I'm looking for an event (for example)
    to tie into which lets me emit HTML inside of the <body> tag. Or, even
    inside the <html> tags, since more than one <body> is (still?)
    technically OK.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Rick Spiewak, Jul 25, 2003
    #4
  5. Rick Spiewak

    Rick Spiewak Guest

    I am successfully using Bruce's suggestion. One subtlety - the routine gets
    called extra times. I found I can avoid this by using:

    ' Prevent double-painting of screen - wait for Render event

    If Not Rendering Then Exit Function

    Rendering = False



    where "Rendering" is a boolean flag set to true in the Render override:



    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

    Rendering = True

    MyBase.Render(writer)

    End Sub



    "abacnet" <> wrote in message
    news:%...
    > What about using a protected variable in the code behind (protected
    > mstrMyVariable as string="") then fill it by whatever value you want at

    any
    > time. Then somewhere in your HTML code add <% =mstrMyVariable %>(you may
    > need to add quotes) . I use this and it works fine.
    >
    >
    > "bruce barker" <> wrote in message
    > news:%...
    > > a literal control won't work because you cannot nest forms in html. the
    > > easisest way is to write a function that renders the html and call from

    > the
    > > page:
    > >
    > > <body>
    > > <% RenderBuyForm(); %>
    > > <form runat=server id=myform>
    > > .....
    > > </form>
    > > </body>
    > >
    > >
    > >
    > >
    > > "Ken Cox [Microsoft MVP]" <> wrote in message
    > > news:en#...
    > > > Off the top of my head, I wonder if adding a Literal server control to

    > > hold the
    > > > content would serve your purpose? It is made to sit inside the

    existing
    > > > server-side <form>. Maybe I've missed something?
    > > >
    > > > Ken
    > > >
    > > > "Rick Spiewak" <> wrote in message
    > > > news:...
    > > > I need to generate a "buy" button as part of an ASP.NET page - this

    > > consists
    > > > of a small HTML form with hidden fields, conforming to the

    requirements
    > of
    > > a
    > > > merchant credit card processor. PayPal is similar.
    > > >
    > > > I'm succeeding in doing this by using Writer.Write to emit my HTML, at

    > > least
    > > > as far as getting it to work.
    > > >
    > > > However, depending on where I put MyBase.Render(Writer), I get my HTML
    > > > either before the header or after the end of the body of the HTML

    > > generated
    > > > by ASP.NET. Oddly enough, both Netscape and IE seem to be happy to

    > handle
    > > > this. But, it looks ugly and is probably non-compliant.
    > > >
    > > > Anyone have any ideas as to how to split the difference and get my

    added
    > > > HTML form into the <body>?
    > > >
    > > > TIA
    > > >
    > > > Rick Spiewak
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Rick Spiewak, Aug 1, 2003
    #5
  6. Hi Rick,

    I am glad to hear that. Thank you for sharing the knowledge in the
    newsgroup.

    Best Regards,
    Lewis

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    | Reply-To: "Rick Spiewak" <>
    | From: "Rick Spiewak" <>
    | References: <>
    <en#>
    <#>
    <#>
    | Subject: Re: How to insert dynamically generated HTML into the <body> of
    an ASP.NET page?
    | Date: Fri, 1 Aug 2003 01:27:04 -0400
    | Lines: 98
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | Message-ID: <eEhAM2#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: 209-6-243-228.c3-0.frm-ubr1.sbo-frm.ma.cable.rcn.com
    209.6.243.228
    | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:164027
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | I am successfully using Bruce's suggestion. One subtlety - the routine
    gets
    | called extra times. I found I can avoid this by using:
    |
    | ' Prevent double-painting of screen - wait for Render event
    |
    | If Not Rendering Then Exit Function
    |
    | Rendering = False
    |
    |
    |
    | where "Rendering" is a boolean flag set to true in the Render override:
    |
    |
    |
    | Protected Overrides Sub Render(ByVal writer As
    System.Web.UI.HtmlTextWriter)
    |
    | Rendering = True
    |
    | MyBase.Render(writer)
    |
    | End Sub
    |
    |
    |
    | "abacnet" <> wrote in message
    | news:%...
    | > What about using a protected variable in the code behind (protected
    | > mstrMyVariable as string="") then fill it by whatever value you want at
    | any
    | > time. Then somewhere in your HTML code add <% =mstrMyVariable %>(you
    may
    | > need to add quotes) . I use this and it works fine.
    | >
    | >
    | > "bruce barker" <> wrote in message
    | > news:%...
    | > > a literal control won't work because you cannot nest forms in html.
    the
    | > > easisest way is to write a function that renders the html and call
    from
    | > the
    | > > page:
    | > >
    | > > <body>
    | > > <% RenderBuyForm(); %>
    | > > <form runat=server id=myform>
    | > > .....
    | > > </form>
    | > > </body>
    | > >
    | > >
    | > >
    | > >
    | > > "Ken Cox [Microsoft MVP]" <> wrote in
    message
    | > > news:en#...
    | > > > Off the top of my head, I wonder if adding a Literal server control
    to
    | > > hold the
    | > > > content would serve your purpose? It is made to sit inside the
    | existing
    | > > > server-side <form>. Maybe I've missed something?
    | > > >
    | > > > Ken
    | > > >
    | > > > "Rick Spiewak" <> wrote in message
    | > > > news:...
    | > > > I need to generate a "buy" button as part of an ASP.NET page - this
    | > > consists
    | > > > of a small HTML form with hidden fields, conforming to the
    | requirements
    | > of
    | > > a
    | > > > merchant credit card processor. PayPal is similar.
    | > > >
    | > > > I'm succeeding in doing this by using Writer.Write to emit my HTML,
    at
    | > > least
    | > > > as far as getting it to work.
    | > > >
    | > > > However, depending on where I put MyBase.Render(Writer), I get my
    HTML
    | > > > either before the header or after the end of the body of the HTML
    | > > generated
    | > > > by ASP.NET. Oddly enough, both Netscape and IE seem to be happy to
    | > handle
    | > > > this. But, it looks ugly and is probably non-compliant.
    | > > >
    | > > > Anyone have any ideas as to how to split the difference and get my
    | added
    | > > > HTML form into the <body>?
    | > > >
    | > > > TIA
    | > > >
    | > > > Rick Spiewak
    | > > >
    | > > >
    | > > >
    | > >
    | > >
    | >
    | >
    |
    |
    |
     
    Lewis Wang [MSFT], Aug 1, 2003
    #6
    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. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    451
    Steve C. Orr [MVP, MCSD]
    Jun 3, 2004
  2. Mark Sandfox
    Replies:
    2
    Views:
    4,185
    Mark Sandfox
    Jun 24, 2004
  3. rgouge
    Replies:
    0
    Views:
    366
    rgouge
    Jul 29, 2005
  4. Brian
    Replies:
    2
    Views:
    255
  5. Replies:
    4
    Views:
    192
    Gomolyako Eduard
    Oct 18, 2005
Loading...

Share This Page