ECatsBlog
  • Home
  • Web Dev
  • Reviews
  • Thoughts
  • ASP
  • SQL
  • Browser
  • Mobile
  • Cloud
  • CMS
  • ECommerce
  • App Hacks
  • Fixes
  • Mapping
  • 3D Printing
  • XAML
  • SEO

Categories

  • 3D Printing (1)
  • App Hacks (3)
  • ASP (19)
  • Browser (12)
  • Cloud (10)
  • CMS (7)
  • ECommerce (6)
  • Fixes (2)
  • Mapping (1)
  • Mobile (12)
  • Reviews (70)
  • SEO (9)
  • SQL (12)
  • Thoughts (59)
  • Uncategorized (1)
  • Web Dev (91)
  • XAML (9)

Archives

  • June 2019 (1)
  • January 2019 (175)
  • December 2018 (47)

ASP .NET and PayPal Buttons

When Written: Dec 2009

Whilst building an ASP .NET web site the other day we had a need to put a PayPal ‘pay now’ button, which is normally simple enough. The web site of the provider ( PayPal in this case ) provides a wizard that creates  the HTML code for the button and the associated <FORM> tag that you simply copy and paste in to your web page. However with ASP .NET all the web pages have a <FORM> in them already to deal with user clicks and asynchronous postbacks to the server.

If you use Master Pages for applying common code to your web pages it is normal for the <FORM> tag to be in this Master Page which means that you can’t  easily remove it and you can’t have one form embedded within another. So what do you do? A look round the forums showed that this is a common problem and like most problems there are more than one solution. Some of these verged from nasty ‘kludges’ of removing the Master Page and manually adding the code that was in the Master Page to the web page with the troublesome button on, but this would then mean that the web page would not update automatically if any changes were made to the Master Page, not at  all ideal.

Another solution was very slick in that it created a FORM object in memory and the button exists in this, so when clicked the action of this form would be committed. The code to achieve this was fairly involved, and it was at this moment that I came across a different and much simpler solution. All you need to do is to remove the form code around the button and change the ‘PostbackUrl’ on the asp:imagebutton to the url defined in the removed form’s ‘action’ so when a user clicks this button a submit type event is fired and the data on the form is sent via a ‘POST’ to this url.

The slight drawback with this method is that all the data from any other form objects on the page would also be sent  to this URL but that is not normally a problem.  I do like simple solutions.

Article by: Mark Newton
Published in: Mark Newton

  • Previous ADO .NET Entity Data Model- Wotsthat?2 years ago
  • Next Adding asynchronous calls2 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • IIS8 SMTP setup
  • 3D printing the Ness of Brodgar
  • Which phone is best?
  • Mobile Apps
  • HTML5 mobile app dev – part 5

Recent Comments

  • HP Deskjet 3755 Wireless Printer Setup on Windows 10 phone and HERE Maps – Fixed!
2021 ECatsBlog. Donna Theme powered by WordPress