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>
[prev. Lesson]  VB.net - Your First Library
     [next Lesson]  User Control:Version2 Amazon Book Covers/Links/Details

User Controls For Amazon.com books
by Charles Carroll and Steve Smith

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=/experiments/usercontrols/testbooks.aspx

<Test Script Below>


<%@ Register TagPrefix="bookshow" tagname="cover" src="books.ascx"%>
<html><head>
<title>CodeShow Test</title>
</head>
<body>
<bookshow:cover id="book1" ISBN="0517887290" idpromocode="learnasp" height=105 width=80 runat="server"/><br>
<bookshow:cover id="sally" ISBN="0385484992" promocode="learnasp" height=105 width=80 runat="server"/><br>
<bookshow:cover ISBN="0451169530" promocode="easterseals" height=105 width=80 runat="server"/><br>
<bookshow:cover ISBN="0553283685" promocode="learnasp" height=105 width=80 runat="server"/><br>
</body>
</html>

The User Control:

filename=/experiments/usercontrols/books.ascx


<script runat="server" language="vb">
Public isbn AS string
Public height AS integer=80
Public width as integer=55
public localGraphic as string
public promocode as string="learnasp"
Sub Page_Load(Src As Object, E As EventArgs) 
    book.NavigateUrl="http://www.amazon.com/exec/obidos/ISBN=" & ISBN & "/" & promocode
    IF len(localgraphic)=0 THEN
        bookcover.ImageURL="http://images.amazon.com/images/P/" & ISBN & ".01.MZZZZZZZ.jpg"
    ELSE
        bookcover.ImageURL=localgraphic
    END IF
    bookcover.Alternatetext="Amazon:" &  isbn
    bookcover.height=Unit.Pixel(height)
    bookcover.width=Unit.pixel(width)
End Sub
</script>
<asp:hyperlink id="book" runat="server">
<asp:Image ID="bookcover" runat="server" />
</asp:hyperlink>


Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site