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:
- Create a wrapper MasterPage that includes everything that will be common on all of your pages except for your
- Create a ContentPlaceHolder inside your wrapper MasterPage
- Create a child MasterPage that calls the wrapper as its MasterPage
- Inside the child’s
<asp:Content>tag, put your form
- 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.