.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

ASP.NET, PayPal, and Google Checkout: The Solution!

After searching high and low for a solution to the PayPal/Google Checkout dilemma (trying to submit your shopping cart to them using ASP.NET was a problem because you couldn’t use nested forms), I have come up with a (non-kludgy) technique that will work, and actually provides the developer with another level of abstraction that could potentially be useful elsewhere.

EDIT: 2/27/2008 – There is a much better way to integrate PayPal and Google Checkout. Please see my new article, ASP.NET: How To Integrate Both Google Checkout and PayPal In 3 Steps. The article on the page you are currently viewing should be used as a reference on how to nest MasterPages.

What’s this technique? Nested MasterPages, of course! Here’s what I did step by step:

  1. Create a wrapper MasterPage that includes everything that will be common on all of your pages except for your <form> tag
  2. Create a ContentPlaceHolder inside your wrapper MasterPage
  3. Create a child MasterPage that calls the wrapper as its MasterPage
  4. Inside the child’s <asp:Content> tag, put your form
  5. Once you’ve placed your form inside your child MasterPage’s content tag, create a ContentPlaceHolder, and then add a content page (.aspx page)

Be sure to reference your wrapper from your child MasterPage’s page directive, like so:
<%@ Master Language="VB" MasterPageFile="~/masterWrap.Master" CodeFile="masterChild.master.vb" Inherits="masterChild" %>

Once you’ve set up this level of abstraction, you can create another child master page without the <form runat="server"> tag in it, and do all your necessary PayPal and Google Checkout form construction! I usually use literals to create the forms and their hidden fields on the server side.

I created this abstraction very easily in about five minutes in an application that was using MasterPages already, so it’s not hard to retrofit if you need to. Remember also that a child can only reference its direct parent (and that MasterPages render LAST!), so if you need pass info to your wrapper MasterPage, create properties in the MasterPages up the line and pass them along in the Page_Load subroutine (don’t forget to set up MasterPage referencing).

So for those of you looking for a method to use PayPal and Google Checkout within your current MasterPage setup, this may solve your woes! It solved mine!

NOTE: By doing this, you will lose design-time support in (at least) Visual Studios 2005, since it does not support nested MasterPages in design mode. I guess everything comes with a price.

kick it on DotNetKicks.com


September 28, 2007 - Posted by | ASP.NET, Google, MasterPages, PayPal, Tips & Tricks |


  1. […] Status: Solved (9/28/07)! Solution: See this post. […]

    Pingback by Problems With PayPal/Google Checkout and Nested Forms « .NET Discussion | September 28, 2007 | Reply

  2. […] unknown wrote an interesting post today!.Here’s a quick excerptAfter searching high and low for a solution to the PayPal/Google Checkout dilemma (trying to submit your shopping cart to them using ASP.NET was a problem because you couldn’t use nested forms), I have come up with a (non-kludgy) … […]

    Pingback by GadgetGadget.info - Gadgets on the web » ASP.NET, PayPal, and Google Checkout: The Solution! | September 28, 2007 | Reply

  3. Hi, I’m quite new to .NET and masterpage. But I’m excited over your solution to this ongoing paypal problem. Could you explain more in details on how you created the MasterPage step by step?

    What I did was:

    Created MasterPage
    Created .aspx, linked to masterpage
    Added paypal forms in.

    But it still didn’t work.


    Comment by Geneva | September 28, 2007 | Reply

  4. Hey Geneva –

    What you need to do is create NESTED MasterPages, so basically, create your main MasterPage (without the FORM RUNAT=SERVER tag), then create another MasterPage. Your second MasterPage will essentially function as both a content page and a MasterPage. It will function as a content page because you will be putting your FORM RUNAT=SERVER tag inside ASP:CONTENT tags, but it will function as a MasterPage because you will create your content pages from it (your child MasterPage) that require a FORM RUNAT=SERVER tag. Once you have this set up, go back to your first MasterPage (that doesn’t have the FORM RUNAT=SERVER tag) and create a content page from that. Then put your PayPal forms in that content page, and everything should work!

    Comment by Some.Net(Guy) | September 28, 2007 | Reply

  5. Cool, that means from now on, all my content pages will have to reference to the child master page?

    Comment by Geneva | September 28, 2007 | Reply

  6. Thanks. I get what you mean. But will I be able to dynamically modify paypal variables if I were to do it from MasterPage (Master)? Because it seems like it has no forms and thus not possible to include any server controls.

    Comment by Geneva | September 28, 2007 | Reply

  7. Hey, I got it to work using a quick hack.

    What I had was a Literal, and then forming my own paypal button link. It didn’t use to work because it was within a form.

    A quick solution: Add a dummy right before the paypal link. It is able to break out of the current form, and enable paypal’s form to work.

    Of course, the downside is obvious, but it may work for certain people that could do away with the downside.

    It works like charm!

    Comment by Geneva | September 28, 2007 | Reply

  8. Your MasterPage(Master) [by the way, I like that syntax :)] should rarely be referenced for anything other than template stuff. Anything page-specific should be done in the content page itself. Now, if you are going to add PayPal/Google Checkout forms, you can still have a FORM RUNAT=SERVER on that page – just put one in somewhere above or below your PP/GCO forms. My method simply gives you the ability to choose to put a FORM RUNAT=SERVER on all your pages or not without really doing a lot of extra work.

    Comment by Some.Net(Guy) | September 28, 2007 | Reply

  9. I think what you meant was a dummy /FORM tag? If so, this *may* work, but yes, there are plenty of downsides. My technique is slightly more scalable, but if yours works for you, I’m glad I could at least get you thinking on the right track 🙂

    Comment by Some.Net(Guy) | September 28, 2007 | Reply

  10. Because I had to change the variables of paypals’ dynamically. To do that it has to be within a form because it needs a server control.

    By the way, can your solution handle this problem? Yes mine work, but I’d prefer a more complete solution and I’m looking at yours 😛

    Comment by Geneva | September 28, 2007 | Reply

  11. Actually, that’s not true. Not all server controls need to be in a FORM RUNAT=SERVER tag. I create all my hidden inputs dynamically using a literal, which does not need to be in a FORM RUNAT=SERVER tag. It’s a pretty good solution that can be modified dynamically.

    Comment by Some.Net(Guy) | September 28, 2007 | Reply

  12. Through trial and error, I have recently discovered that it is only the first nested form that will not work properly in an ASP.NET page.

    If you proceed your PayPal form with an empty form, it will then post as expected whether in a standalone .ASPX page or a Content Pane with a Master Page.

    That simple trick should make ASP.NET/PayPal developers happy.

    Gordon Bell

    Comment by Gordon Bell | October 1, 2007 | Reply

  13. Through trial and error, I have recently discovered that it is only the first nested form that will not work properly in an ASP.NET page.

    If you proceed your PayPal form with an empty form, it will then post as expected whether in a standalone .ASPX page or a Content Pane with a Master Page.

    <form id=”aspnetform” runat=”server”>


    <form method=”post” action= “https://www.paypal.com/cgi-bin/webscr”>
    <input type=”hidden” name=”cmd” value=”_xclick”>
    <input type=”hidden” name=”business” value=”my@email.com”>
    <input type=”hidden” name=”item_name” value=”Item name”>
    <input type=”hidden” name=”item_number” value=”1234″>
    <input type=”hidden” name=”amount” value=”19.95″>
    <input type=”hidden” name=”no_shipping” value=”1″>
    <input type=”submit” value=”Buy Now”>


    That simple trick should make ASP.NET/PayPal developers happy.

    Gordon Bell

    Comment by Gordon Bell | October 1, 2007 | Reply

    • Thank you. You are the best.

      Comment by Rohim Uddin | August 18, 2009 | Reply

    • TOOO GOOD working so good

      Comment by Adeel | September 19, 2009 | Reply

  14. […] Nested MasterPages: ID Mangling After I implemented the ASP.NET PayPal solution for the order submission part of my site, I noticed that my color picker (which relies heavily on […]

    Pingback by ASP.NET Nested MasterPages: ID Mangling « .NET Discussion | October 19, 2007 | Reply

  15. Gordon, thank you very much! That works like a charm 🙂

    Comment by Mike Kingscott | December 7, 2007 | Reply

  16. […] that is invisible until a button is pressed. The contents of the panel are two non-server forms for PayPal and Google Checkout. Before I converted the site to MasterPages and AJAX, the functionality performed correctly, but […]

    Pingback by ASP.NET and AJAX: Error Making Forms Visible With UpdatePanel « .NET Discussion | January 18, 2008 | Reply

  17. […] you’re saying, “Wait a second, haven’t you already written an article on this?” you are correct. However, the solution I present to you here is infinitely simpler and […]

    Pingback by ASP.NET: How to Integrate Both Google Checkout and PayPal In 3 Steps « .NET Discussion | February 27, 2008 | Reply

  18. hai sir,

    I want to keep Google Check out button in Data List .And again i want access the Clik event of check button.pls send solution to morampudy23@rediffmail.com as early as possible

    Comment by venkat55720 | April 22, 2008 | Reply

  19. venkat55720 –

    I’m not sure how I would include the GCO button in a GridView (I think that’s what you mean) since submitting the button means submitting all hidden inputs, and there’s no dynamic way to submit Buy Now buttons for GCO as their code is all encrypted. You may want to have your button just go to a checkout page with the item clicked as your hidden input.

    Sorry I can’t be of more help, but I am not sure what you’re doing is possible dynamically.

    Comment by Some.Net(Guy) | April 22, 2008 | Reply

  20. //

    <asp:Label ID=”lblTitle” runat=”server” SkinID=”ModuleBoldLabelHeading” Text=”>

    <asp:Image ID=”imgProduct” runat=”server” ImageUrl=” />

    <asp:Label ID=”lblDescription” runat=”server” SkinID=”LabelText” Text=”>

    <asp:Label ID=”lblSpecificationText” runat=”server” SkinID=”LabelText” Text=”>

    <asp:Label ID=”lblPrice” runat=”server” SkinID=”ModulePriceLabel” Text=”>

    <asp:Label ID=”Label1″ runat=”server” SkinID=”ModuleBoldLabelHeading” Visible=”false” Text=”>
    <asp:Label ID=”Label2″ runat=”server” SkinID=”ModulePriceLabel” Text=”>


    i am doing this in Xml when i click on Google Chek out button the check out form must open but i am not getting
    i am not sure this is correct for ex i wrote like this pls provide source code (if any )

    Comment by Venkateswara Rao | April 24, 2008 | Reply

  21. Can you give the full details about google checkout API

    Comment by Don | May 12, 2008 | Reply

  22. Talk about a huge waste of time getting a simple donate button to work in a master page. Thank you for the dummy form solution.

    Comment by fed-up-with-all-the-asp-hoop-jumpin | June 11, 2008 | Reply

  23. If you like to host this PayPal-Integrated Checkout page website, you can visit http://www.asphostcentral.com. I have my shopping cart website hosted on this host and everything works perfectly.

    Furthermore, this host truly supports PayPal payment and you can see it from the Order Registration System. It is all about PayPal and it is very easy to integrate on your .NET application

    Comment by Stephen | August 3, 2008 | Reply

  24. Another option: Include a second ContentPlaceholder in your MasterPage below the ending form tag. On your Subscription page, drop your PayPal / Google Checkout / Amazon Simple Pay forms into ContentPlaceHolder2 instead of ContentPlaceHolder1, and you’re good to go.



    Comment by Jeb | August 19, 2008 | Reply

  25. Ok wait – I found this solution using javascript that is SOOOOOOO brilliantly simple compared to any of this MasterPage and Ghostform lunacy that I can’t believe this isn’t the top search returned on Google for this issue:

    Basically you just need to remove the form tags from the Paypal HTML and then replace the image button with an A link around an image. In the A link you have javascript that resets “theForm” which is ASP.NET’s main form to point to Paypal instead of back to your page.


    Comment by David | October 11, 2008 | Reply

  26. Just one slight wee little problem with that… you’re depending on client side code to submit your form. If your user has JS turned off, you make no money. If you read my solution here:


    you’ll see that there’s a much easier and much better way to do it than relying on hacked Javascript. That may be why the solution is not as touted as you may think.

    Thanks for the comment!

    Comment by Some.Net(Guy) | October 13, 2008 | Reply

  27. I know a shopping cart software that can support Google Checkout and Paypal very easily.

    We can use osCommerce for this purposes, the software can be obtain free from any type of hosting plan at http://www.seekdotnet.com

    And you can install the software and start to use Paypal and Google Check out right away

    Comment by Richard | January 16, 2009 | Reply

  28. i want to paypal account

    Comment by juno | May 5, 2009 | Reply

  29. […] /> If you develop in some older .NET frameworks, try solution with nested MasterPages.Website Payments Library Toolkit for .NETPayPal allows developers to download Website Payments […]

    Pingback by ernestovo zákoutí : PayPal library | June 15, 2009 | Reply

  30. […] that elusive nugget I needed to solve the problem. I thought I had found it when I came across the nested master page hack – keep the outer master page stripped of any form tag and then just use it for the page with the […]

    Pingback by Solution to ASP.NET Form - PayPal Problem | May 24, 2010 | Reply

  31. Thank you very much

    Comment by İlker Uzunoğlu | April 26, 2012 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: