views:

991

answers:

6

Coming from a Classic ASP background, I'm used to multiple forms on a page, but this clearly limited in a ASP.NET page.

However, I have a situation where I have a form that gathers input from the user, saves the data to a DB, and afterwards I want to render (and tweak the values of) a special form that posts to the PayPal website.

If the PayPal form's field values were static, there would be no problem, but since I want to manipulate the form server-side (to tweak the qty, desc, price fields etc) this will be a problem.

I was considering redirecting to a different page after writing to the DB, and I suspect this would work fairly well, but it's a bit of extra effort that may be unneccessary.

It has also been suggested to me that I could programmatically render a different form, depending on where in the cycle I am. That is, use a placeholder, and on Page_Load I would add a DB Form (complete with child controls) initially, and the PayPal form after a Postback.

This scenario has got to be a common one for you guys, so I'm looking for opinions advice and any relevant code samples if you have preferred approach.

I know I can get by, but this project is a learning vehicle so I want to adopt what passes for best practice.

Thanks in advance...

Chris

A: 

A basic approach is to use two panels on the page - one for the first form and another for the second.

You can change the visibility property of these panels depending on which form you want to display (during page_load or any time before rendering).

Oded
+3  A: 

You can have multiple forms, it's just only one form may have the runat="server" attribute.

There are a bunch of answers to getting paypal to work; but as it's a learning vehicle that may be cheating. In all honesty I'd look at the full blown paypal API rather than use the somewhat simplistic forms method (with the added advantage that it should stretch your learning more).

Otherwise yes, setup a HTML form outside of the server side form, and add a literal into it and write the bits and pieces in there.

blowdart
A: 

Maybe I'm misunderstanding the question, but can't you simply have 2 divs inside the form, where only one is visible at any time. e.g.

<form id="Form1" method="post" runat="server">
    <div id="getUserInput" visible="true">
          <asp:button id="btnSubmitFirst" />
    </div>
    <div id="doSubmissionToPaypal" visible="false">
          <asp:button id="btnSubmitSecond" />
    </div>
</form>

Then, in btnSubmitFirst_Click:

 doSubmissionToPaypal.visible=True
 getUserInput.visible = false

Something along those lines?

RB
A: 

The reason that I can't simply use 2 divs in one form is because the Paypal form posts to a different page - it doesn't postback to the same page. I could perhaps change the target in code ('); it's already been considered... but I'm trying to sample opinions in case there is a particular approach that I haven't considered, that is more elegant or easy to use.

Re: full API - yes, I know what you mean, but the project is time-sensitive, so I'm trying to keep it simple this time around. It's not a complex e-commerce site; just need to be able to accept payment for a very limited set of items.

CJM
A: 

A workaround for this paypal is to use the Paypal Integration Code as Paypal is not always the most friendly to integrate. The hard work is basically done for you.

naspinski
I'll have a look at this, but since this is a learning exercise, I'd like to do it 'manually' if possible.
CJM
A: 

I have another question.

I work with a CMS which requires that there is a form tag surround the whole page.

<body>
<form runat="server" id="CMSForm">

<p>PAGE CONTENT</p>

</form>
</body>

I would like to be able to do this

<body>
<form runat="server" id="CMSForm">

<p>PAGE CONTENT</p>
<form action="http://www.domain.com" method="post">
 FORM STUFF
</form>

</form>
</body>

Is this possible?

I'm not 100% certain, but I don't think it will like a form-within-a-form. But I expect you could programmatically change the action of the CMS form to achieve what you want.
CJM