How to get past embedding a html form for paypal buttons asp.net

后端 未结 3 1163
盖世英雄少女心
盖世英雄少女心 2021-01-28 03:01

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 payp

相关标签:
3条回答
  • 2021-01-28 03:15

    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

    0 讨论(0)
  • 2021-01-28 03:17

    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);
        }
    }
    
    0 讨论(0)
  • 2021-01-28 03:20

    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.

    0 讨论(0)
提交回复
热议问题