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

R

Rick Spiewak

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
 
K

Ken Cox [Microsoft MVP]

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

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
 
B

bruce barker

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

Rick Spiewak

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

Rick Spiewak

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
 
L

Lewis Wang [MSFT]

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" <[email protected]>
| From: "Rick Spiewak" <[email protected]>
| References: <[email protected]>
<en#[email protected]>
<#[email protected]>
<#[email protected]>
| 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#[email protected]>
| 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
|
|
|
| | > 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.
| >
| >
| > | > > 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>
| > >
| > >
| > >
| > >
message
| > > | > > > 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
| > > >
| > > > | > > > 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
| > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top