Product Detail Page

The Product Detail page displays the details about a specific product. The product displayed is the one corresponding to the ProductID parameter that was carried from the ProductsList.aspx page. All of the code is contained in the Page_Load() method.

The Page_Load() method starts by converting the ProductID parameter into an integer. It then instantiates a ProductsDB object. A ProductDetails structure is obtained by calling the ProductsDB.GetProductDetails() method with the product ID as an argument to the method. The user interface objects are then populated. Table 8.2 shows the user interface objects that are populated.

Table 8.2. The User Interface Objects That Display the Product Details






This holds the product description text.



This holds the single unit cost for the product.



This holds the name of the product.



This holds the catalog number of the product.



This contains the product image that will be displayed.



This links the product to the AddToCart.aspx page.


User Control

This is a user control that contains the list of reviews.


User Control

This is a user control that contains the list of items that user who bought this product also bought.

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, and so on). Two of the server controls, however, are custom IBuySpy 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 among multiple developers.

Listing 8.5 shows the Page_Load() method in C# and VB.

Listing 8.5 The Page_Load() Method That Populates the User Interface Objects for the Product Detail Page


 void Page_Load(Object sender, EventArgs e) {     // Obtain ProductID from QueryString     int ProductID = Int32.Parse(Request.Params["ProductID"]);     // Obtain Product Details     IBuySpy.ProductsDB products = new IBuySpy.ProductsDB();     IBuySpy.ProductDetails myProductDetails =       products.GetProductDetails(ProductID);     // Update Controls with Product Details     desc.Text = myProductDetails.Description;     UnitCost.Text = String.Format("{0:c}", myProductDetails.UnitCost);     ModelName.Text = myProductDetails.ModelName;     ModelNumber.Text = myProductDetails.ModelNumber.ToString();     ProductImage.ImageUrl = "ProductImages/" +       myProductDetails.ProductImage;     addToCart.NavigateUrl = "AddToCart.aspx?ProductdocText">VB

 Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)  ' Obtain ProductID from QueryString  Dim ProductID As Integer = CInt(Request.Params("ProductID"))  ' Obtain Product Details  Dim products As IBuySpy.ProductsDB = New IBuySpy.ProductsDB()  Dim myProductDetails As IBuySpy.ProductDetails = _    products.GetProductDetails(ProductID)  ' Update Controls with Product Details  desc.Text = myProductDetails.Description  UnitCost.Text = String.Format("{0:c}", myProductDetails.UnitCost)  ModelName.Text = myProductDetails.ModelName  ModelNumber.Text = myProductDetails.ModelNumber.ToString()  ProductImage.ImageUrl = "ProductImages/" & _    myProductDetails.ProductImage  addToCart.NavigateUrl = "AddToCart.aspx?ProductID=" & ProductID  ReviewList.ProductID = ProductID  AlsoBoughtList.ProductID = ProductID End Sub 

ASP. NET Solutions - 24 Case Studies. Best Practices for Developers
ASP. NET Solutions - 24 Case Studies. Best Practices for Developers
ISBN: 321159659
Year: 2003
Pages: 175 © 2008-2017.
If you may any questions please contact us: