By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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" <ri*********@mindspring.com> wrote in message
news:OZ**************@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

Nov 17 '05 #2

P: n/a
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]" <BA************@sympatico.ca> wrote in message
news:en**************@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" <ri*********@mindspring.com> wrote in message
news:OZ**************@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

Nov 17 '05 #3

P: n/a

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!
Nov 17 '05 #4

P: n/a
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" <ab*****@hotmail.com> wrote in message
news:%2****************@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" <no***********@safeco.com> wrote in message
news:%2****************@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]" <BA************@sympatico.ca> wrote in message
news:en**************@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" <ri*********@mindspring.com> wrote in message
news:OZ**************@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



Nov 17 '05 #5

P: n/a
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" <ri*********@mindspring.com>
| From: "Rick Spiewak" <ri*********@mindspring.com>
| References: <OZ**************@TK2MSFTNGP10.phx.gbl>
<en**************@TK2MSFTNGP12.phx.gbl>
<#E**************@TK2MSFTNGP11.phx.gbl>
<#0**************@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: <eE**************@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" <ab*****@hotmail.com> wrote in message
| news:%2****************@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" <no***********@safeco.com> wrote in message
| > news:%2****************@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]" <BA************@sympatico.ca> wrote in
message
| > > news:en**************@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" <ri*********@mindspring.com> wrote in message
| > > > news:OZ**************@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
| > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.