0

I am trying to find a way to add paypal donation button to asp.net webform, since it is wrapped around form which i cant add. Is there a way to add it. Or just a link button for the same.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="xxxx">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
VDWWD
  • 35,079
  • 22
  • 62
  • 79
Learning
  • 19,469
  • 39
  • 180
  • 373
  • Possible duplicate of [Multiple forms on ASP.NET page](http://stackoverflow.com/questions/91350/multiple-forms-on-asp-net-page) – madoxdev Jan 05 '17 at 13:41

1 Answers1

2

There are a couple of things you can do.

Make a static HTML page with the form and use an Iframe on the aspx page.

<iframe src="paypal.html"></iframe>

Do the form post on a button click from code behind (code not tested, but there are many more examples here on SO as how to make a form post in code behind)

protected void Button1_Click(object sender, EventArgs e)
{
    using (WebClient client = new WebClient())
    {
        byte[] response = client.UploadValues("https://www.paypal.com/cgi-bin/webscr", new NameValueCollection()
        {
            { "cmd", "_s-xclick" },
            { "hidden", "xxxx" }
        });

        string result = Encoding.UTF8.GetString(response);
    }
}

You can try to make a link with the form values as a query string. There are references to this on various forums.

<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=xxxx">PayPal</a>

And finally you could communicate with the PayPal API

https://developer.paypal.com/docs/api/

VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • I used the iframe concept as i wast not sure about how it was going to behave. But it work fine and can control the design aspect of it also. Anyways thanks for your option which also include the iframe one. – Learning Jan 07 '17 at 10:30
  • Onlything i am not sure if `{ "cmd", "_s-xclick" }, { "hidden", "xxxx" }` if this will work. link could be teh most easy but i have to play around to see if it works as you have suggest. I am surprise to see why paypal doesnt have link based button – Learning Jan 07 '17 at 10:32
  • I've up-voted this for the query-string method - I appreciate it may not be the most robust / future-proof, but it does the job as of writing. Thanks – Andrew Birks Apr 15 '19 at 14:22