开发者

Generating a POST request for PayPal button in C# ASP.net

I'm trying to allow a web form to use a PayPal buy it now. The relevant page is here.

Based on which radio button a user selects, depends on which paypal button they are "redirected" to. The subscriptions are easy - they are just a simple redirect.

The last option, requires a user select a venue. For this, i require to use the form below:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="10956105">
<table>
<tr><td><input type="hidden" name="on0" value="Venue">Venue</td></tr><tr><td>
<input type="text" name="os0" maxlength="60"></td></tr>
</table>
<input type="image" src="https://www.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

But of course, I want to do it without using that form.

What I have so far is:

 if (singleOneOff.Checked)
            {
                paypalForm.Text = getPaypalForm(venueSelect.SelectedItem.Text);
                var strJS = getPayPalPostJS("_xclick");
                paypalJs.Text = strJS;
                var xxx = "dd";
            }

This determines if that particular radio button was ticked.

getPaypalForm

private String getPaypalForm(string venue)
{
    StringBuilder strForm = new StringBuilder();
    strForm.Append(@"<form action=""https://www.paypal.com/cgi-bin/webscr"" name=""_xclick"" method=""post"">");
    strForm.Append(@"<input type=""hidden"" name=""cmd"" value=""_s-xclick"">");
    strForm.Append(@"<input ty开发者_开发技巧pe=""hidden"" name=""hosted_button_id"" value=""10956105"">");
    strForm.Append(@"<input type=""hidden"" name=""on0"" value=""Venue"">");
    strForm.Append(@"<input type=""text"" name=""os0"" value=""{0}"" maxlength=""60"">");
    strForm.Append("</form>");

    return String.Format(strForm.ToString(), venue);
}

getPayPalPostJS

private String getPayPalPostJS(string strFormId)
{
    StringBuilder strScript = new StringBuilder();
    strScript.Append("<script language='javascript'>");
    strScript.Append("var paypalForm = document.forms.namedItem('{0}');");
    strScript.Append("paypalForm.submit();");
    strScript.Append("</script>");
    return String.Format(strScript.ToString(), strFormId);
}

However, if i select the radio button, and a venue, and press the button, nothing happens....

Any ideas where i've gone wrong?

I followed this guide: http://www.netomatix.com/development/postrequestform.aspx


Here's a much cleaner, server-side solution to the ASP.NET/PayPal single form problem:

http://codersbarn.com/post/2008/03/08/Solution-to-ASPNET-Form-PayPal-Problem.aspx


The root of the problem is that ASP.Net web forms wrap everything on the page inside of one large <form> tag. Your paypal code is rendering a nested form and that doesn't work.

Read this question for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜