Paypal Form Ruins My ASP.NET webforms layout -> How to Solve?
Asked Answered
F

2

5

I am a student who is doing up a simple website in asp.net. My problem is, I wish to integrate Paypal on one of the pages, but asp.net has the ridiculous <form runat="server"> that is getting in my way. I am building a simple site layout using blueprint css, a very basic three-column layout. However, I need my main content section to be able to use the paypal form (buy now button), and the other areas of the site to use user controls, which I presume requires them to be wrapped in that irritating form tag. In fact, I would like to have a sitemap path control at the top of the main section of the site: something very basic. How might I achieve that? My problem is: I can't put the Paypal button in the form, and I don't know how to shift a 4th div into place. I am not even sure how divs and forms stack on each other.

Could I have some help please?

The page with the problem is: http://clubofpep.org/sandbox/sandbox_Alumni.aspx.

Finale answered 14/9, 2011 at 16:12 Comment(0)
S
8

Contrary to popular belief, you can have more than one form on ASP.Net webforms pages. What you cannot do is have more than one form with runat="server", nest a second form inside ASP.Net's main form, or use asp.net server controls outside the main form.

Therefore, to integrate a separate paypal form with the rest of an asp.net webforms page, you have to make sure that you can put it either before or after all of the asp.net web controls on the page, and then edit the aspx markup to make sure your paypal form is completely outside of asp.net's form.

The other thing is that a quick web search shows a multitude of paypal controls written for asp.net that will work with the required asp.net form to submit the payment. You could always try one of those.

Shanahan answered 14/9, 2011 at 16:17 Comment(3)
I was wondering if the <form> tag was treated as a separate div, because I having some problems with styling. Also, I don't seem to find the "multitude of paypal controls". What I find mostly is 2. The "free" control from ComponentOne which requires a PayPal Business Account, and the not-so-cheap ASP.Net Paypal Button control. You know of any others?Myranda
@Finale - A form tag is a block level element, just like any other block level element. So, yes, it's kind of like another div tag. A google for asp.net paypal control returns results for me with at least 4 different controls on the first page.Shanahan
@Joel, excellent explanation. I'm posting another alternative I came across - creating a custom HtmlForm :)Lucerne
L
1
namespace CustomForm
{
    public class GhostForm : System.Web.UI.HtmlControls.HtmlForm
    {
        protected bool _render;

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

        public GhostForm()
        {
            //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);
        }
    }
}

USAGE:

ASPX:

<%@ Register TagPrefix="CF" Namespace="CustomForm" Assembly="CustomForm" %>
<body>
    <CF:GhostForm id="mainForm" runat="server">
    ...
</body>

<img src="https://www.sandbox.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"> <asp:Button ID="checkoutBtn" runat="server" OnClick="CheckButton_Click"
    Text="Checkout" Width="100" CausesValidation="false" /> 

Code-Behind:

protected void Page_Load(object sender, EventArgs e)
{
    ...
    // Workaround for PayPal form problem
    GhostForm mainForm = new GhostForm();
    mainForm.RenderFormTag = false;
    // Go ahead and submit to PayPal :)
}
Lucerne answered 22/9, 2011 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.