Dominik G
Dominik G

Reputation: 1479

ASP.Net WebForms + Paypal Form

I am currently trying to integrate PayPal into our existing Web Application.

The Web Application is using ASP.NET WebForms.

Since in WebForms we have a form element around (almost) everything, I wonder how to integrate a PayPal Button which uses a form itself.

Is there any way to do it?

Upvotes: 1

Views: 1069

Answers (1)

MikeSmithDev
MikeSmithDev

Reputation: 15797

Yes. I do it in a three step process:

  1. Remove the form tag from the PayPal code since you can't have nested forms.
  2. Add an ID, class, or something to the PayPal button to let you find it in a jQuery function (this example uses an id of paypalbutton).
  3. Add a jQuery script to catch the click and override the form post:

This may need to be modified to work with your specific code (but it may work as is):

$(document).ready(function() {
    $("#paypalbutton").on("click",function(n) {
        n.preventDefault();
        $("#aspnetForm").attr("action","https://www.paypal.com/cgi-bin/webscr");
        $("#aspnetForm").submit(); //or whatever your WebForms form element is called
    });
});

Upvotes: 3

Related Questions