Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 814
  • Last Modified:

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?
0
azyet24
Asked:
azyet24
1 Solution
 
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
 
azyet24Author Commented:
KPMT-Technician,

Do you have a VB.NET version of your code?  
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
KPMT-TechnicianCommented:
Did the VB code work OK for you?

Robert Fidler
Springfield, Missouri
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now