tags:

views:

1458

answers:

4

I confess I am a noob to asp.net and web forms. I'm having an issue incorporating a few PayPal Buy Now buttons on a single page. Basically, the problem is no matter which "Buy Now" button is clicked, the user is taken to paypal to buy the product represented by the last button on the page.

The code for my first button is something like this...

<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ABC123">
<asp:ImageButton runat="server" id="PPImageButton1" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" ImageUrl="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif"/&gt;

My second button is similar to...

<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ABC456">
<asp:ImageButton runat="server" id="PPImageButton2" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" ImageUrl="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif"/&gt;

How can I make the first button send value ABC123 to the PayPal service instead of ABC456?

Thanks in advance.

A: 

It's not your button that sends the value - it's the form it's in, and/or the code behind it. Could you:

  1. Post the form code?
  2. Post the code behind for this page?
Traveling Tech Guy
+1  A: 

The POST content of a button is every input in the FORM tag that surrounds the submit button. So to have each button submit a separate set of hidden fields you need to wrap the button and the desired hidden fields in a separate form:

<form ... >
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ABC123">
<asp:ImageButton runat="server" id="PPImageButton1" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" ImageUrl="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif"/&gt;
</form>

<form ... >
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ABC456">
<asp:ImageButton runat="server" id="PPImageButton1" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" ImageUrl="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif"/&gt;
</form>
Remus Rusanu
Thanks for the reply. I basically screwed up in my explanation in that I didn't provide adequate detail. It is a SharePoint site and when I tried to add a second Form tag (to create the 1st button, I received an error stating nested forms were not supported in ASP.NET. So, I pulled the <form> out and the first button worked OK. Then when I added the 2nd button, I found the issue.
MikeW
So is it working now with distinct forms for each product?
Remus Rusanu
<form><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="ABC12">asp:ImageButton runat="server" id="PPImageButton1" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" ImageUrl="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif"/></form><form><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="ABC34"><asp:ImageButton runat="server" id="PPImageButton2" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" ImageUrl="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif"/></form>
MikeW
My last comment is the current code which does not work. The first button appears to fucntion properly while the second button only refreshes the page.
MikeW
Remus, you comments helped. I recieved some bad advice before posting here. I added the approprite switches to the <form> line and it appears to be working fine now. Thank you for setting me on the proper course.
MikeW
A: 

My noob solution for this was to cut each of the buy-it-now buttons and its associated fields out of the aspx page, and put each set in a separate html page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>first button</title>
</head>

<body>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="paypal">
<input type="hidden" value="_s-xclick" name="cmd" /> <input type="hidden" value="???????" name="hosted_button_id" /> 
<table>
<tbody>
<tr>
<td><input type="hidden" value="Member name" name="on0" />Member name</td>

<td><input maxlength="60" size="30" name="os0" /></td></tr>
<tr>
<td><input type="hidden" value="Membership No. (if known)" name="on1" />Membership No. (if known)</td>
<td><input maxlength="60" size="6" name="os1" /></td></tr></tbody></table>
<input type="image" alt="PayPal - The safer, easier way to pay online." src="https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif"  name="submit" /> <img height="1" alt="" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" border="0"/> </form>

</body>
</html>

In the place in the aspx page where you removed the button and other fields, insert an iframe which points to the html page like this:

<iframe width="600" height="" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="mybuttonpage1.htm"></iframe>
A: 

Here is a solution the the multiple form problem when using PayPal with ASP.NET:

http://www.codersbarn.com/post/2008/03/08/Solution-to-ASPNET-Form-PayPal-Problem.aspx

IrishChieftain