I have a form with an object data source that pulls data from a service reference. Here's the form and the routine from my .cs. It works fine when I enter a valid part number. When a part number is not found by the service reference, it throws back an exception. I'd like to handle this exception, but my try..catch block is not working, it's still throwing "A critical error has occurred. Exception has been thrown by the target of an invocation" and my page stops working. What is the proper way to handle the exception error?
<%@ Control Language="C#" Inherits="MyStockLookup.MyStockLookup" CodeFile="~/DesktopModules/StockLookup/StockLookup.ascx.cs" %>
SelectMethod="GetItemByID"
TypeName="StatusLookupRef.ItemServiceClient"
onselected="ObjectDataSource1_Selected">
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"
CellSpacing="2" DataSourceID="ObjectDataSource1" EnableModelValidation="True"
GridLines="Both">
Item ID:
Item Description:
Quantity On Hand:
Text='<%# Bind("qty_on_hand") %>' />
Quantity Available:
Text='<%# Bind("qty_available") %>' />
protected void StockLookup(string sNoData)
{
try
{
ObjectDataSource1.DataBind();
}
catch (ModuleLoadException ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
catch (PageLoadException ex)
{
Exceptions.ProcessPageLoadException(ex);
}
}