Link to home
Start Free TrialLog in
Avatar of azyet24
azyet24Flag for United States of America

asked on

Repeater - Paypal button not working

I have a repeater that shows the products from a database.  There is a button that sends the item to paypal's shopping cart.  This works fine outside of the repeater (if I statically enter the link) but will not work inside the repeater.  The button inside the repeater is linking to the parent page instead of picking up the paypal link in the form tag.  Here's an example:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
                            <div align="center">
                                <input type="hidden" name="cmd" value="_cart">
                                <input type="hidden" name="business" value="email@aol.com">
                                <input type="hidden" name="item_name" value="And The End Shall Come">
                                <input type="hidden" name="item_number" value="10001">
                                <input type="hidden" name="amount" value="15">
                                <input type="hidden" name="cn" value="Special Instructions (optional">
                                <input type="hidden" name="no_note" value="1">
                                <input name="submit" type="image" src="images/buy_now.jpg" alt="Make payments with PayPal - it's fast, free and secure!"
                                    border="0">
                                <input type="hidden" name="add" value="1">
                            </div>
                        </form>

Any ideas?
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Dear azyet24,
Probably, you can combine the submitted value in hidden fields as a string, then use javascript to post the form manually using javascript.
eg:

'your button onclick event, you can amend it accordingly

Sub btnClick
  Dim s as string
  s="<form target="paypal" action='https://www.paypal.com/cgi-bin/webscr' method='post'>"
  s &="<input type='hidden' name='cmd' value='_cart'>"
  .... others hidden fields
  s &="</form>"
  s &="<script>document.forms[0].submit();</script>"
  Response.write(s);
End Sub
/// <summary>
///   How to accomplish the paypal's buy it now button with out multiple forms.
/// </summary>
/// <example>
///   <asp:HyperLink id="buyItNow" runat="server" BorderWidth="0"
///      ImageUrl="~/images/add_to_cart.gif"
///      NavigateUrl="<%# GeneratePayNowURL( Container.DataItem ) %>"  
///      ToolTip="Make payments with PayPal - it's fast, free and secure!" />      
/// </example>
/// <param name="dataItem">
///    This is the DataSource that is driving you repeater.
/// </param>
/// <returns>
///    A URL to paypal using query string to pass values.
/// </returns>
protected string GeneratePayNowURL( object dataItem )
{
   System.Text.StringBuilder url = new System.Text.StringBuilder();
   url.Append( @"javascript: location.href='" );
   url.Append( @"https://www.paypal.com/cgi-bin/webscr?" );
   url.Append( String.Format( "&cmd={0}", DataBinder.Eval( dataItem, "cmd" ).ToString() ) );
   url.Append( String.Format( "&business={0}", DataBinder.Eval( dataItem, "business" ).ToString() ) );
   url.Append( String.Format( "&item_name={0}", DataBinder.Eval( dataItem, "item_name" ).ToString() ) );
   url.Append( String.Format( "&item_number={0}", DataBinder.Eval( dataItem, "item_number" ).ToString() ) );
   url.Append( String.Format( "&cn={0}", DataBinder.Eval( dataItem, "cn" ).ToString() ) );
   url.Append( String.Format( "&no_note={0}", DataBinder.Eval( dataItem, "no_note" ).ToString() ) );
   url.Append( String.Format( "&add={0}", DataBinder.Eval( dataItem, "qty" ).ToString() ) );
   url.Append( @"';" );
   return url.ToString();
}

Give this a shot.

Robert Fidler
Springfield, Missouri
Avatar of azyet24

ASKER

KPMT-Technician,

Do you have a VB.NET version of your code?  
ASKER CERTIFIED SOLUTION
Avatar of KPMT-Technician
KPMT-Technician
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did the VB code work OK for you?

Robert Fidler
Springfield, Missouri
Forced accept.

Computer101
EE Admin