Working with Data in ASP.NET 2.0 - Handling BLL and DALLevel Exceptions
In the Overview of Editing and Deleting Data in the DataList tutorial, we created a DataList that offered simple editing and deleting capabilities. While fully functional, it was hardly userfriendly, as any error that occurred during the editing or deleting process resulted in an unhandled exception. For example, omitting the product’s name or, when editing a product, entering a price value of “Very affordable!”, throws an exception. Since this exception is not caught in code, it bubbles up to the ASP.NET runtime, which then displays the exception’s details in the web page. As we saw in the Handling BLLand DALLevel Exceptions in an ASP.NET Page tutorial, if an exception is raised from the depths of the Business Logic or Data Access Layers, the exception details are returned to the ObjectDataSource and then to the GridView. We saw how to gracefully handle these exceptions by creating Updated or RowUpdated event handlers for the ObjectDataSource or GridView, checking for an exception, and then indicating that the exception was handled.
Our DataList tutorials, however, aren’t using the ObjectDataSource for updating and deleting data. Instead, we are working directly against the BLL. In order to detect exceptions originating from the BLL or DAL, we need to implement exception handling code within the codebehind of our ASP.NET page. In this tutorial, we’ll see how to more tactfully handle exceptions raised during an editable DataList’s updating workflow. Note: In the An Overview of Editing and Deleting Data in the DataList tutorial we discussed different techniques for editing and deleting data from the DataList, Some techniques involved using an ObjectDataSource for updating and deleting. If you employ these techniques, you can handle exceptions from the BLL or DAL through the ObjectDataSource’s Updated or Deleted event handlers.
Step 1: Creating an Editable DataList
Before we worry about handling exceptions that occur during the updating workflow, let’s first create an editable DataList. Open the ErrorHandling.aspx page in the EditDeleteDataList folder, add a DataList to the Designer, set its ID property to Products, and add a new ObjectDataSource named ProductsDataSource. Configure the ObjectDataSource to use the ProductsBLL class’s GetProducts() method for selecting records; set the dropdown lists in the INSERT, UPDATE, and DELETE tabs to (None).
…
Website: www.podgoretsky.com | Filesize: 480kb
No of Page(s): 8
Click here to download Working with Data in ASP.NET 2.0 - Handling BLL and DALLevel Exceptions.
Related Tutorial
Tags: .NET, data binding, data connections, exception handling, web control
Comments
Leave a Reply