Class Frameworks in VB .NET - Presentation Layer (Page 4 of 5 )
Now that the business objects are built, we’re back to our presentation layer – the ASP.NET page. As you will see in a moment, the functions we need to perform on the page are now a breeze because all the logic has already been encapsulated into business and data access components.
First of all, in the Page_Load event of editProduct.aspx page, we will create a new Product object:
objProduct = New Product(Request.Params("ProductID"))
This one line of code initializes objProduct with all information we require for display on the page. Then all we need to do is set the Textbox and Label control values:
Notice the use of objProduct.Supplier.propertyName syntax, which very typical for object-oriented frameworks. This is possible because Supplier is exposed as a read-only property of Product class and the information is accurate because each product holds only related-by-ID Supplier object.
When user enters all information and clicks “Update” button, all the code we need to update the database with latest data takes up exactly 4 lines:
And there it is. The Save function of the Product object will propagate all changes made by users back to the database table automatically. Once the page has redirected back to product list, the users will see the information updated on their screen.