473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ObjectDataSource and Exception handling

I hope someone may have some insight to this issue...

I would like to know how to properly implement exception handling using
the ObjectDataSource control.

Specfically, I am doing an insert using an object that calls a web
service to accomplish this. The service returns a message to the
Insert method that indicates that the insert can't be accomplished
because it is trying to insert a duplicate key value. So, I simply
want to raise a custom exception ("NotUniqueException"). All this
works great, however, I can't for the life of me figure out where to
catch this exception.

The ObjectDataSource Control Inserting event takes place before the
method is called and the Inserted event after the fact. The button on
the FormView has a command of "Insert" so the insert method is "just
called from somewhere"...

Any ideas?

Thanks.
charlie

Nov 19 '05 #1
2 5630
When there is an exception in your class' Update method and you don't catch
it (meaning it's unhandled), the ODS catches it and presents it in the Updated
event of the ODS. The ObjectDataSourceStatusEventArgs passed to the Updated
event has an Exception property to let you know if an exception was thrown.
If you then set ObjectDataSourceStatusEventArgs.ExceptionHandled to true,
then nothing else special happens. If you leave ObjectDataSourceStatusEventArgs.ExceptionHandled
= false, then you'll see the normal unhandled exception behavior in ASP.NET.

So, in short, handle the Updated event, check the Exception object, show
your user the error somehow, and set ExceptionHandled = true.

HTH

-Brock
DevelopMentor
http://staff.develop.com/ballen
I hope someone may have some insight to this issue...

I would like to know how to properly implement exception handling
using the ObjectDataSource control.

Specfically, I am doing an insert using an object that calls a web
service to accomplish this. The service returns a message to the
Insert method that indicates that the insert can't be accomplished
because it is trying to insert a duplicate key value. So, I simply
want to raise a custom exception ("NotUniqueException"). All this
works great, however, I can't for the life of me figure out where to
catch this exception.

The ObjectDataSource Control Inserting event takes place before the
method is called and the Inserted event after the fact. The button on
the FormView has a command of "Insert" so the insert method is "just
called from somewhere"...

Any ideas?

Thanks.
charlie


Nov 19 '05 #2
How could I have missed that? Your answere was right on the money,
thank you.

c

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press...
1
by: Jeremy Brown | last post by:
I am binding an ObjectDataSource to a GridView, and I want to be able to trap and respond to an exception within the data source whenever the grid is being populated. Since this is controlled...
0
by: Richard Carpenter | last post by:
I am working on a small project in which I am trying to implement a data access layer through the use of a project dataset schema. Data integrity and normalization will be handled through the use...
2
by: Manjunath | last post by:
HI, How to catch custom exception using ObjectDataSource Control. I am calling Business Layer method through ObjectDataSource control, when Business layer method throws exception which will be...
2
by: Kevin Frey | last post by:
One of my chief criticisms of validators in an ASP.NET page is that they can result in a developer re-implementing much of the "business logic" of a transaction at the page level. Assuming we...
1
by: =?Utf-8?B?cm9zczYxMw==?= | last post by:
I really hope this is not a case of "this silly thing will never work".....lots of time invested in troubleshooting this already. I have created a standard ASP.NET web form (.aspx) with several...
1
by: MattC | last post by:
Hi, Given an ObjectDataSource and GridView declared as: <asp:ObjectDataSource runat="server" ID="FullCategoryList" TypeName="AD.App_Code.CategoryDataMapper" SelectMethod="GetCategories"...
1
by: Allan Ebdrup | last post by:
I have a asp.net v2 website that runs fine on our development server. I have published the website to a stage server and it runs fine, but when I publish it to production I get the following error:...
0
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.