views:

67

answers:

3

Hi,

I have some experience of using paypal with an asp.net website, however this issue has me really stumped.

Root of the problem: You cant embed the html form for the paypal button inside your page form.

Original solution: Originally my website was using multiple aspx pages so I could simply arrange my form tags so that they weren't embedded inside one another.

My website now uses a master aspx page which draws in different ascx controls. This means that I do not have the option of arranging the form tags around the page so need a work around.

NB. I have looked all over the place for simple solutions but it is a jungle out there, paypal is a nightmare. I did find something on ghost form which is all in c#. Might help...

Thanks in advance for any help....

+1  A: 

Submit the PayPal information using their APIs rather than submitting a form directly to them.

That way you can keep everything as part of a single form and add a little more robustness around the PayPal input and validation.

PayPal: SDKs and Downloads

Justin Niessner
A: 

Had this issue with another payment provider also. You could either use their API, or you could work around it by:

  • Making the checkout button a standard imagebutton
  • Running something like ClientScript.RegisterStartupScript() to output both HTML and Javascript. The HTML should be the actual form with all hidden fields and proper id. The javascript is code which would execute on page load and submit the page.

i.e. ClientScript.RegisterStartupScript(Me.GetType(), "PaypalSubmit", "<AllMarkUp><GoesHere><script>And.Javascript</script>", False)

Hope this helps, otherwise you could use the web service API. By taking this approach you are performing a postback, outputting the HTML form (outside the .NET form because it is at the bottom of the page) and then relying on the javascript to actually submit it.

Kyle B.
A: 

Here's something that will work for you. In your code-behind:

// Workaround for PayPal form problem
CustomForm mainForm = new CustomForm();
mainForm.RenderFormTag = false;

Create a custom form class which overrides the HtmlForm class:

public class CustomForm : System.Web.UI.HtmlControls.HtmlForm
{
    protected bool _render;

    public bool RenderFormTag
    {
        get { return _render; }
        set { _render = value; }
    }

    public CustomForm()
    {
        //By default, show the form tag
        _render = true;
    }

    protected override void RenderBeginTag(HtmlTextWriter writer)
    {
        //Only render the tag when _render is set to true
        if (_render)
            base.RenderBeginTag(writer);
    }

    protected override void RenderEndTag(HtmlTextWriter writer)
    {
        //Only render the tag when _render is set to true
        if (_render)
            base.RenderEndTag(writer);
    }
}
IrishChieftain