E:\web\learnaspcom\htdocs\freebook\learn\ubtoc.xml LearnAsp.com - ASP ASP.net Free Lessons
Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
xxx

Programatically Creating User Controls For Amazon.com books
by Pete Draigh

This page demonstrates a very useful in the real-world User Control to encapsulate a hyperlink and book cover to buy something from Amazon.com and to use one's promotional code to make a little money on the deal.

Simple page:

   filename=/students/PeteDraigh/amazonarray.aspx

<Test Script Below>


<%@ Register TagPrefix="pete" TagName="AmazonLink" Src="amazon.ascx" %>
<script language="vb" runat="server">
    sub page_load(s as object, e as eventargs)
        dim isbnarr(6) as string
        dim i as integer
    
        isbnarr(0) = "1861007035"
        isbnarr(1) = "0060199032"
        isbnarr(2) = "0764310720"
        isbnarr(3) = "0896585670"
        isbnarr(4) = "0618007016"
        isbnarr(5) = "0060245867"

        Dim c1 As Control

        dim whatever as control
        whatever=Page.FindControl("books")

        for i = 0 to 5
            c1 = LoadControl("amazon.ascx")
                CType(c1, AmazonLink).isbn = isbnarr(i)
                CType(c1, AmazonLink).height = "105"
                CType(c1, AmazonLink).width = "80"
                CType(c1, AmazonLink).promocode = "petedraigh"
            whatever.controls.Add(c1)
        next
   
    end sub

</script>


<html>
<head>
<title>Amazon Example</title>
</head>

<body>

<asp:placeholder id="books" runat="server" />

The User Control:

filename=/students/PeteDraigh/amazon.ascx


<%@ Control ClassName="AmazonLink" %>

<script language="VB" runat="server">
    public isbn as string
    public height as string
    public width as string
    public promocode as string


Sub Page_Load(Src As Object, E As EventArgs) 

    dim link as string
    
    link = "<a href='http://www.amazon.com/exec/obidos/ISBN=" & isbn & "/" & promocode & "'>"
    link &= "<img src='http://images.amazon.com/images/P/" & isbn & ".01.MZZZZZZZ.jpg' height='" & height & "' width='" & width & "'></a>"

    results.text = link
End Sub
</script>


<asp:literal id="results" runat="server" />
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.