Sunday, December 6, 2009

PayPal buttons in ASP.net 2.0

Getting a simple PayPal Buy It Now button working in an ASP.net 2.0 site was trickier than I thought. Because the entirety of an ASP.net 2.0 'page' essentially becomes the content within a HTML form tag ( <form>), the PayPal Buy It Now, with it's own HTML form conflicts.

Just placing the PayPal code within a basic ASP.net page, then clicking the PayPal 'Buy Now' button would refresh the current page. I was chasing popup blocking and cross-domain issues for a few minutes before I realized the page was just posting back to itself.

Ended up using the 'IFrames' solution described at
PayPal Button (Pay Pal Button ) SOLUTIONS!!!! - ASP.NET Forums
just cause I could bang it out in about an hour tonight. Maybe will look at the devloper kits in the future.

Also added in the hyperlink as a backup (if a customer does block pop-ups, or some other strict security setting in the future)

Also, the post to paypal didn't work when debugging locally. The page would open, but none of the post parameters were going across. Figured it was a local browser setting, and it worked when running from the live host, so I didn't dig any further on that one.

No comments: