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

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

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

    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 Guest

  2. Similar Questions and Discussions

    1. unable to execute a javascript in a dynamically generated HTML
      Hi, I have a dynamically generated HTML code rendered on a browser instance created though code (AxSHDocVw.AxWebBrowser instance) . I have...
    2. extract body-content from HTML page online
      Hi everybody, I need to include an online web page in my own one. My first attempt was to include() that page. This way all the HTML framework...
    3. Fit to Page Option in Printing HTML generated by ASP
      Hey all I have an asp which page which generates an html page. When I print the page 2-3 lines go to the next page. If there a way in...
    4. How to Dynamically insert JavaScript into a Page Header
      Hello, From a user control what is the best way ( other than static ) to insert JavaScript include in the Head of an HTML page <head> <script...
    5. What is the prefered way to insert HTML in a page.
      In ASP you use <% =HtmlString %> but in ASP.NET this can cause some problems if you are using page inheritance. What is the prefered way to...
  3. #2

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

    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" <rickspiewak@mindspring.com> wrote in message
    news:OZvkaIjUDHA.2224@TK2MSFTNGP10.phx.gbl...
    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] Guest

  4. #3

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

    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]" <BANSPAMken_cox@sympatico.ca> wrote in message
    news:en#YfMjUDHA.1872@TK2MSFTNGP12.phx.gbl...
    > 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" <rickspiewak@mindspring.com> wrote in message
    > news:OZvkaIjUDHA.2224@TK2MSFTNGP10.phx.gbl...
    > 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 Guest

  5. #4

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


    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Rick Spiewak Guest

  6. #5

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

    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" <abacnet@hotmail.com> wrote in message
    news:%2301efnrUDHA.1872@TK2MSFTNGP12.phx.gbl...
    > 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" <nospam_brubar@safeco.com> wrote in message
    > news:%23EQoHTkUDHA.2200@TK2MSFTNGP11.phx.gbl...
    > > 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]" <BANSPAMken_cox@sympatico.ca> wrote in message
    > > news:en#YfMjUDHA.1872@TK2MSFTNGP12.phx.gbl...
    > > > 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" <rickspiewak@mindspring.com> wrote in message
    > > > news:OZvkaIjUDHA.2224@TK2MSFTNGP10.phx.gbl...
    > > > 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 Guest

  7. #6

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

    Hi Rick,

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

    Best Regards,
    Lewis

    Get Secure! - [url]www.microsoft.com/security[/url]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    | Reply-To: "Rick Spiewak" <rickspiewak@mindspring.com>
    | From: "Rick Spiewak" <rickspiewak@mindspring.com>
    | References: <OZvkaIjUDHA.2224@TK2MSFTNGP10.phx.gbl>
    <en#YfMjUDHA.1872@TK2MSFTNGP12.phx.gbl>
    <#EQoHTkUDHA.2200@TK2MSFTNGP11.phx.gbl>
    <#01efnrUDHA.1872@TK2MSFTNGP12.phx.gbl>
    | 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#VDHA.1896@TK2MSFTNGP12.phx.gbl>
    | 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!TK2MSFTN GP12.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" <abacnet@hotmail.com> wrote in message
    | news:%2301efnrUDHA.1872@TK2MSFTNGP12.phx.gbl...
    | > 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" <nospam_brubar@safeco.com> wrote in message
    | > news:%23EQoHTkUDHA.2200@TK2MSFTNGP11.phx.gbl...
    | > > 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]" <BANSPAMken_cox@sympatico.ca> wrote in
    message
    | > > news:en#YfMjUDHA.1872@TK2MSFTNGP12.phx.gbl...
    | > > > 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" <rickspiewak@mindspring.com> wrote in message
    | > > > news:OZvkaIjUDHA.2224@TK2MSFTNGP10.phx.gbl...
    | > > > 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] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139