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?
azyet24Asked:
Who is Participating?
 
KPMT-TechnicianCommented:
''' <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 Function GeneratePayNowURL(ByVal dataItem As Object) As String
     Dim url As 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()
End Function

Robert Fidler
Springfield, Missouri
0
 
David H.H.LeeCommented:
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
0
 
KPMT-TechnicianCommented:
/// <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
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
azyet24Author Commented:
KPMT-Technician,

Do you have a VB.NET version of your code?  
0
 
KPMT-TechnicianCommented:
Did the VB code work OK for you?

Robert Fidler
Springfield, Missouri
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.