|
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
<%@ 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>
|