Adding PayPal donate button to ASP.NET page, the easy way

I’ve been looking all over the Internets for a simple straightforward way of adding a donate button to my ASP.NET page but all I could find were bloated plugins or simple GET forms. Since I had quite a huge parameter called “encrypted” in my PayPal button generated code, sending it in the URL might not be such a good idea, as many browsers are limited in that area. In my case the “encrypted” value was around 2500 bytes.

I also considered that PayPal might have a good reason to need the form sent via POST so I finally decided to build the form dynamically in JavaScript.

Don’t forget to paste in the value of the “encrypted” field from your generated code on PayPal. Here’s the JS code:

function Donate()
	var myform = document.createElement("form");
	myform.action = "";
	myform.method = "post"; = "_blank";

	var cmd = document.createElement("input"); = "cmd";
	cmd.type = "hidden";
	cmd.value = "_s-xclick";

	var encrypted = document.createElement("input");
	encrypted.type = "hidden"; = "encrypted";
	encrypted.value = "";

	var image = document.createElement("input");
	image.type = "image";
	image.src = "";
	image.border = "0"; = "submit";
	image.alt="PayPal - The safer, easier way to pay online!";

	//Most probably this can be skipped, but I left it in here since it was present in the generated code
	var pixel = document.createElement("image");
	pixel.border = "0";
	pixel.src = "";
	pixel.width = "1";
	pixel.height = "1";



And here is the image you need to place anywhere on the ASP.NET page:

<img src=""�
alt="PayPal - The safer, easier way to pay online!"�

Good Luck!

Leave a Reply

Your email address will not be published.