Codingmentor.com- Web coding and development forums- discuss JavaScript, HTML, PHP, CGI, scripting, and more!
 
Sitemap
Link Exchange
Link Exchange More
 
Sponsored Links
Search
 
Free Link Exchange   | Coding Forums
 

In Part 1 of this article, Pay Dirt: Using PayPal's Web Controls, I introduced the idea of getting paid for products or services using PayPal's pluggable controls in your own Web pages. As part of the demonstration, I added a "Make a Donation" button to my Web site. The "Make a Donation" button made it possible for readers to make an optional donation when they downloaded some of the tens of thousands of lines of sample code on my site. Since then, a few readers were generous enough to make donations.

Using PayPal with these copy and paste buttons may be just the ticket for you: sell your poems, create an instant online garage sale, or actually sell a product or service. However, for high-traffic commercial Web sites, you may want more control than the basic copy-and-paste that HTML has to offer.

In this article, I show you how to use the PayPal ASP.NET Web Controls and build your own storefront in ASP.NET. There are several controls in the downloadable toolkit. We focus on a couple of core controls needed for offering products, managing a cart, and getting paid.

Your Pair 'o Pennies

To experiment with the examples in this article you first need to perform a couple of preparatory steps. You need a PayPal account and a couple of test accounts in the PayPal sandbox; you'll find those instructions in Pay Dirt: Using PayPal's Web Controls. There is no cost involved in creating a PayPal account or sandbox accounts.

Note: PayPal is a product offering of EBay. The links referenced in this article were provided to me by David Nielsen at PayPal and should be the latest versions of the portal and e-commerce starter kit. Here are the text links in case you have difficulty following the hyperlinks in the article text. The e-commerce starter kit can be found at http://www.paypal.com/aspdotnet and the PayPal ASP.NET web controls can be found at http://www.persistent.com/paypal/aspdotnet/PayPal%20ASP.NET%20Web%20Controls%20(1.0.5).msi.

After you create a PayPal account and test accounts you can download the PayPal ASP.NET Web Controls and the PayPal Commerce Starter Kit. You need the PayPal ASP.NET Web Controls to experiment with the code in this article and the PayPal Commerce Starter Kit is a complete e-commerce example based on the IBUYSPY portal and PayPal Web controls. Once you have mastered the fundamentals in this article, you can explore the commerce starter kit and use that as a starting point for your own e-commerce Web site.

Before you begin, install the PayPal web controls and make sure that the controls show up in the VS.NET toolbox.

Displaying Your Wares

For the purposes of our discussion, I limit our focus to selling products on the Internet. You could use the PayPal Web controls to sell a service or offering a recurring-fee subscription, but here we create a simple storefront.

The first thing to do is define a means of presenting the products to sell on a Web page. To maintain focus, let's take some reasonable shortcuts. Here is an overview of the goals we need to accomplish:

Create an inventory. In a real application, we probably would want to store the inventory in a database, but we aren't going to take an ADO.NET detour here. Provide an image and caption to show customers our products. We need to assign a name, number, and a price for each product, for tracking purposes. Define a way to organize and display our products.

For simplicity, I use a strongly typed collection of hard-coded product information and an ASP.NET user control and DataList to display all of the products. The user control plays the role of a template that contains controls to display a single product, and the PayPal ASP.NET Web controls; the DataList uses the item template to repeat the controls in the user control for each product.

Listing 1 defines the Item class that represents a single product. Listing 2 contains the typed collection of Items, and Listing 3 and Figure 1 show the code-behind and the visual implementation of the user control.

Listing 1: The product-item class.

  public class Item
  {
    private string itemImageUrl;
    private string itemName;
    private string itemNumber;
    private string itemCaption;
    private double itemPrice;

    public static Item CreateItem(string imageUrl,
      string itemName, string itemNumber, string itemCaption,
      double itemPrice)
    {
      return new Item(imageUrl, itemName, itemNumber, 
        itemCaption, itemPrice);
    }

    public Item(){}

    public Item(string itemImageUrl, string itemName, 
      string itemNumber, string itemCaption, double itemPrice)
    {
      this.itemImageUrl = itemImageUrl;
      this.itemName = itemName;
      this.itemNumber = itemNumber;
      this.itemCaption = itemCaption;
      this.itemPrice = itemPrice;
    }

    public string ItemImageUrl
    {
      get{ return itemImageUrl; }
      set{ itemImageUrl = value; }
    }

    public string ItemName
    {
      get{ return itemName; }
      set{ itemName = value; }
    }

    public string ItemNumber
    {
      get{ return itemNumber; }
      set{ itemNumber = value; }
    }

    public string ItemCaption
    {
      get{ return itemCaption; }
      set{ itemCaption = value; }
    }

    public double ItemPrice
    {
      get{ return itemPrice; }
      set{ itemPrice = value; }
    }
  }

Listing 2: The implementation of the typed ItemCollection, including hard-coded product information.

  public class ItemCollection : System.Collections.CollectionBase
  {
    public static ItemCollection CreateTest()
    {
      ItemCollection o = new ItemCollection();
      o.Add(Item.CreateItem("~/images/csharp_dev_guide.jpg", 
        "Advanced C#", 
        "1234", "Advanced C# Programming Book", 39.99));
      o.Add(Item.CreateItem("~/images/ExcelVBA.jpg", 
        "Excel VBA 2003 Progrmaminers Guide", "1235", 
        "Visual Basic for Applications programmers guide for Excel 2003", 
        39.99 ));
      o.Add(Item.CreateItem("~/images/powercoding.jpg", 
                "Visual Basic .NET Power Coding", "1236",  
        "Advanced Visual Basic .NET programming book (autographed copy)", 
        41.99));
      o.Add(Item.CreateItem("~/images/spyrograph.jpg", "Spyrograph Game", 
        "1237", "Spyrograph for Windows (source code included)", 
        19.99));
      o.Add(Item.CreateItem("~/images/VBNETUnleashed.jpg", 
        "Visual Basic .NET Unleashed",
        "1238", "Visual Basic .NET programming book.", 39.99));
      return o;
    }

    public Item this[int index]
    {
      get{ return (Item)List[index]; }
      set{ List[index] = value; }
    }

    public int Add(Item value)
    {
      return List.Add(value);
    }
  }

The static method CreateTest populates our typed collection with pre-defined products. This same implementation would work fine by populating the typed collection from a database or by replacing the typed collection with a DataSet.

Listing 3: The code-behind for the user control.

namespace PayPal
{
  using System;
  using System.Data;
  using System.Drawing;
  using System.Web;
  using System.Web.UI.WebControls;
  using System.Web.UI.HtmlControls;

  /// 
  ///    Summary description for BuyNow.
  /// 
  public class BuyNow : System.Web.UI.UserControl
  {
    protected System.Web.UI.WebControls.Image Image1;
    protected System.Web.UI.WebControls.Label Label1;
    protected PayPal.Web.Controls.AddToCartButton AddToCartButton1;
    protected PayPal.Web.Controls.BuyNowButton BuyNowButton1;

    private void Page_Load(object sender, System.EventArgs e)
    {
      // Put user code to initialize the page here
    }

    public string ItemImageUrl
    {
      get{ return Image1.ImageUrl; }
      set{ Image1.ImageUrl = value; }
    }

    public string ItemName
    {
      get{ return BuyNowButton1.ItemName; }
      set
      { 
        BuyNowButton1.ItemName = value; 
        AddToCartButton1.ItemName = value;
      }
    }

    public string ItemNumber
    {
      get{ return BuyNowButton1.ItemNumber; }
      set
      { 
        BuyNowButton1.ItemNumber = value; 
        AddToCartButton1.ItemNumber = value;
      }
    }

    public string ItemCaption
    {
      get{ return Label1.Text; }
      set
      { 
        Label1.Text = value; 
      }
    }

    public double ItemPrice
    {
      get{ return BuyNowButton1.Amount; }
      set
      { 
        BuyNowButton1.Amount = value; 
        AddToCartButton1.Amount = value;
      }
    }

    [Web Form Designer generated code]
  }
}

The constituent properties in the user control are surfaced using property methods. Each property either binds to the image, label, or one of the PayPal control properties.

C# Primary Sites

The Code Project Whitepapers and code examples by category. Good code resource.
 
DeveloperFusion (C# Directory: U.K. Developer Community)
 
C# Corner
C# developers network: code, downloads, discussions,...
 
C# Help
Help for C# Developers
 
Creating Designable Components for Microsoft Visual Studio .NET Designers
An introduction to using components in C# development. (July 2000 by Shawn Burke, Microsoft Corp.)
 
C# Station
 
DevX Resources
 
C# Friends See whitepapers, a class- "browser" reference, and more... by Salman Ahmed.
 
Lutz Roeder's Programming .NET
Tools and source code examples. Reflector assembly browser, Resourcer, Digger. Also applications and source code.
 
Code Hound C# Search Engine
 
C# Notebook Notebooks, Bookstore, Code, .dll tutorial,..much more
 
CSharpHelp.Com The place for C# developers.
 
Peter Drayton's .NET Goodies
C# Utilities & samples with code.
 

Code Examples

CSharpToday.com
 
A Comparative Overview of C# (Genamics.Com)
 
C# Developer's Search Engine at Code Hound
 
The Code Project (code, tutorials for developers)
 
A Drawing Canvas in C# by Bill Burris (ComponentsNotebook.com)
 
CodeAssist.Com
 
CShrp.Net

C# References


 

C# Resource Directories

Cetus-Links C# Directory
John Smiley's C# page (created July 1, 2000)
csharp-station.com
Joe Mayo's website; Purpose: Source of information, links, and other resources for the C# programming language.

 

C# Tutorials

Boxing and Performance by Eric Gunnerson for Microsoft, MSDN.
 
Compilation and Runtime Execution of a C-Sharp Program by Sudhakar Jalli for c-sharpcorner.com
 
CSharp Station Tutorials
 
C# FAQ for C++ Developers (by Andy McMullen)
 
How to Compile C# Programs and Compiler Switches by Saurabh Nandu for dotnet101.com
 
Introduction to C# (SimonRobinson.Com)
 
Jon Jagger's C# slides now available for free download at Jaggersoft.com
Jon Jagger recently delivered 200+ slides on C# in two presentations at a UK conference in Oxford. He has put the slides on his website (free download, recently updated in line with Beta-2)
 
Online slides and notes for a 5-day course Programming in C# by Jon Jagger
 
Learn-C-Sharp.Com Tutorials&
 
Learning C# (ManagedWorld.Com)
 
Preview of C# (FindTutorials.Com)
 
Serializing Objects in C#
 
The C# Tutorial list at FindTutorials.Com
 
Tutorial list for C# topics (CSharpFree.Com)
(Click on Tutorials)
 

Discussions & Newsgroups

C# Message Board Read instructions at the Message Board home page (next link).
 
Message Boards (gotdotnet.com)
 
Go to news://msnews.microsoft.com/microsoft.public.dotnet.csharp.general to reach microsoft.public.dotnet.dotnet.csharp.general newsgroup.
See the Web interface.
 
The DevX List: newsgroups and discussion forum
 

C# E-Books, Online Books

C# Whitepapers, C# Articles

Deep Inside C#: An Interview with Microsoft Chief Architect Anders Hejlsberg by John Osborn of O'Reilly.com; August 01, 2000
 
Keep Your Data Secure With the New Advanced Encryption Standard (James McCaffrey, November 2003)
 
C# For Beginners
 
What .NET Means to IT Professionals
 
Handling Exceptions in C#
Jose Aniceto (suite101.com); Pub: June 25, 2002
 
Build Web Commerce Apps With C# (DevX)
 
Web Services - Part I - The Basics (dotNET101.com)
 
Using XML To Document C# Code (mantrotech.com/technology/)
 
Operator Overloading article Eric Gunnerson (Microsoft) June 20, 2001
 
Sharp New Language: C# Offers the Power of C++ and Simplicity of Visual Basic by Joshua Trupin
This article at Microsoft.Com assumes you’re familiar with C++ and COM+
 
C#: A Message Queuing Service Application (Carl Nolan, Microsoft Corp.)
 
ECMA C# Language Specification
 
Enumerating Objects With .NET
(Jeffrey Richter, Developer.com)
 
C#: A Message Queuing Application (Carl Nolan, Microsoft Corp.)
 

External Archives of C# Articles

Brief C# History Note

HISTORY: C#, a Java-like programming language, was submitted by Microsoft to the ECMA standards group in mid-2000. On July 11, 2000 Microsoft had a press release announcing the .NET Framework to unite programming languages for Web-based uses.
(This C# Directory began as the first C# Web site on the Internet, and has evolved as more information and references for developers has become available.)


 

Copyright ©  2006 Codingmentor.com All Rights Reserved.