Description: The ProductDetails page displays detailed information about a particular product.
Implementation Notes: This page appears when a user clicks a link to a specific product in the ProductsList.aspx page. The ProductID of the product to display is passed to the page as a URL querystring argument (ie: "ProductDetails.aspx?ProductID=363"). Please review the ProductsList.aspx page to see how this argument is added when constructing the hyperlink to this page.
The ProductsList page logic is encapsulated entirely within its Page_Load event handler. This event handler is called when the page is accessed by a browser client.
Page_Load Event Handler: The Page_Load event handler obtains the specified ProductID parameter using the Params collection of the page's Request object. The Params collection contains all query string, form field, cookie, and server variables sent from a client during an HTTP request. This the typical API through which page developers access arguments when doing page to page navigation transfers.
After converting the ProductID into an Integer, the Page_Load event handler creates an instance of the ProductDB class and calls its GetProductDetails method, passing it the product ID. This method internally uses the usp_ProductDetail stored procedure to fetch the product information from the Adventure Works Cycles database.
Once the product data is fetched from the database, it is pushed into a number of server controls on the page. Most of these server controls are standard ASP.NET ones (labels, images, hyperlinks, etc). Two of the server controls, however, are custom Adventure Works Cycles user controls that we have written to encapsulate the " Review List " of a product, as well as a list of products that people who bought the current product Also Bought. Note that these user controls can be programmatically manipulated (property sets/gets, methods called, events sunk and raised) just like any other standard server control. They provide a very nice way to encapsulate and reuse functionality, as well as to cleanly partition work up among multiple developers.
Add to Cart: The third-to-the-last line of code in the Page_Load event handler dynamically constructs an "Add To Cart" link that, when clicked, adds the product to the user's shopping cart. This link references the AddToCart.aspx page, and passes the ProductID of the product to add as a dynamically-generated querystring argument to the hyperlink.
Note that while it is possible to implement this functionality as an ImageButton that posts back to the ProductsList.aspx page, we choose to implement it this way for the following reasons:
Peformance Notes:
<%@ OutputCache Duration="60" VaryByParam="ProductID" %>