Paypal donate button

Aug 3, 2008 at 6:34 PM
How can I put the button in a page?. There is a form inside a form???
Aug 5, 2008 at 2:42 PM
To what I remember of paypal's donate button, when you login to you paypal account, you have an option to create a button, may it be for payment or donation. Once done, paypal gives you a script that u shld place in whichever part of the site you want to.

That ought to do it.

Sashidhar Kokku
Aug 5, 2008 at 11:09 PM
Yes but ASP.NET wont let you have more than 1 form on the page. There are javascript solutions but I like Jeremy Schneider's Ghost Form -
You can use it in a separate ASP.NET page you create yourself. 
However you will have problems if you try to inherit from BlogBasePage to get your master page rendered.  So I've ended up inheriting from the standard System.Web.UI.Page and then opening the page in a javascript with a separate scaled down style sheet without the full master page style.  The whole thing looks like a popup payment window and works ok.  Of course that defeats the purpose of not using a javascript solution to your original problem but I'm accustomed to the GhostForm so that's how I do it.
Aug 6, 2008 at 2:48 AM
Edited Aug 6, 2008 at 2:57 AM
Other options
  1. Put the form inside an HTML page and load that page as an iframe.
  2. Also you can have more than one form on a server, but only one form can be given the runat="server" attribute.  Also, if you nest a form inside of a form it will work in IE but not firefox.
  3. You can place the paypal button script inside a div outside of the pages form and use CSS to control where it gets displayed on the page.
  4. Use an Image button or hyperlink and manually set the URL yourself...
I do #4... I have this function...

  Function GetCheckoutUrl() As String
        Dim Builder As New System.Text.StringBuilder
        Builder.Append("&item_name=" & Me.ListingType)
        Builder.Append("&item_number=" & Me.ListingID)
        Builder.Append("&amount=" & Me.ListingPrice)
        Return Builder.ToString
    End Function

Which gives me a string like this Listing&item_number=0&amount=0&shipping=0&no_note=1&currency_code=USD&tax=0.00&lc=US&bn=PP-BuyNowBF

Then on the page I have something like this:
<a href='<%=GetCheckOutUrl%>'><img src="" /></a>.  The user clicks the link, and they are sent to the paypal checkout page.

And... In another page, I simply loop through the controls I have inside of a gridview itemtemplate, and build the query string based from the controls inside the itemtemplate, save the order to the database and use a response.redirect to send them to the paypal page. 

Point is you not limited to using forms.  If you set the form action to GET instead of post, at actaully opens the page specified in the forms action with all of the forms control ids append as a query string.  A post does something very similar, except it appends the data after the request headers instead of in the uri stem.
Aug 6, 2008 at 4:06 AM
Here... this takes it further than a simple donate button... It is an example on how you can display multiple pay pal add to cart buttons to a shopping cart built from a gridview.  We use a little bit of javascript to write a <form> tag to an popup and put the inner contents of the gridviews <itemtemplate> inside of the form and post the form to pay pay...

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<script runat="server">
    Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs) Handles Me.Load
        Response.Write("<h1>Alex Higgins PayPal GridView Demo</h1>")
        If Not Page.IsPostBack Then
            Me.GridView1.DataSource = Product.GetProducts
        End If
    End Sub
    Public Class Product
        Private _Id As String
        Public Property Id() As String
                Return _Id
            End Get
            Set(ByVal value As String)
                _Id = value
            End Set
        End Property
        Private _Title As String
        Public Property Title() As String
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property
        Private _Price As Double
        Public Property Price() As Double
                Return _Price
            End Get
            Set(ByVal value As Double)
                _Price = value
            End Set
        End Property
        Public Shared Function GetProducts() As Generic.List(Of Product)
            Dim Products As New Generic.List(Of Product)
            For I As Integer = 0 To 9
                Dim p As New Product
                p.Id = "Item_" & I
                p.Title = "Product " & I
                p.Price = 1 + I * 1.25
            Return Products
        End Function
    End Class

<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>

    <script language="javascript" type="text/javascript">
        function posttopaypal(objid) {
         var obj = document.getElementById("container" + objid);
         var opener ="about:blank");
         opener.document.write("<div style='display:none' ");
         opener.document.write("><form ");
          opener.document.write("<input id='buy' type='submit'");
         opener.document.write("/></form" + "></div" + ">");
         var btn = opener.document.getElementById("buy");;
         return false;

    <form id="form1" runat="server">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                            <div id='<%#"container" & eval("ID")%>'>
                                <%#eval("Title") %>
                                <br />
                                <br />
                                <br />
                                <!-- paypal params-->
                                <input type="hidden" name="cmd" value="_xclick" />
                                <input type="hidden" name="business" value="" />
                                <input type="hidden" name="item_name" value="<%#eval("Title") %>" />
                                <input type="hidden" id="amount" name='amount' value='<%#Double.Parse(Eval("Price")).ToString("C").substring(1)%>' />
                                <input type="hidden" name="item_number" value="<%#eval("ID")%>" />
                                <input type="hidden" name="item_price" value="<%#Double.Parse(Eval("Price")).toString("C").substring(1)%>" />
                                <input type="hidden" name="shipping" value="0" />
                                <input type="hidden" name="no_note" value="1" />
                                <input type="hidden" name="currency_code" value="USD" />
                                <input type="hidden" name="tax" value="0.00" />
                                <input type="hidden" name="lc" value="US" />
                                <input type="hidden" name="bn" value="PP-BuyNowBF" />
                            <p align="center">
                                <input type="image" onclick="return posttopaypal('<%#eval("ID")%>');" id='<%#"btn" & eval("ID")%>'
                                    type="image" alt="Make payments with PayPal - it's fast, free and secure!" src=""
                                    border="0" />

Aug 6, 2008 at 6:06 PM
When creating your PayPal button, PayPal gives you code for "Email" as well.  Just use that as a normal link or image link instead of the form.