Asp Net Objectdatasource Error Handling
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the asp net objectdatasource dataset workings and policies of this site About Us Learn more about asp net objectdatasource parameters Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions asp net objectdatasource typename Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. asp net objectdatasource paging Join them; it only takes a minute: Sign up How to handle an exception is thrown by Select method of ObjectDatasource? up vote 4 down vote favorite I have a Select method connected to an ObjectDatasource, this method might throw an exception and I don't know how to handle it! The problem is that I'm not controlling it. When
Asp Net Objectdatasource Sorting
the page is rendered then the select method is called directly by the ObjectDatasource and an unhandled exception is thrown directly. On the other hand, I don't want to make it return empty collection if it has a problem because the collection might be empty without problems. So, where can I handle the exception? Any other options? .net asp.net objectdatasource share|improve this question asked Jul 25 '11 at 21:02 French Boy 5762920 add a comment| 3 Answers 3 active oldest votes up vote 8 down vote accepted Look at the eventargs on the ObjectDataSource. There should be an e.Exception & e.Results that you can query for the success/error of your select. protected void MyOds_Selected (object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception != null) { // handle exception here. ... //tell the ObjectDatasource that the exception is handled //and don't rethrow it. e.ExceptionHandled = true; } } share|improve this answer edited Jul 25 '11 at 21:37 answered Jul 25 '11 at 21:30 Kirill 2,060916 add a comment| up vote 1 down vote You should s
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Asp Net Objectdatasource Selectmethod
and policies of this site About Us Learn more about Stack Overflow asp net objectdatasource set selectparameters in code the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation asp net objectdatasource datatable Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/6822308/how-to-handle-an-exception-is-thrown-by-select-method-of-objectdatasource only takes a minute: Sign up asp.net ObjectDataSource error handling up vote 1 down vote favorite I have objectdatasource and I am trying to find a way to capture the error that is thrown by the SELECT method. anyone idea how it can be done? Page level error handling is preferred, not capturing error at the application_error in global.asax thanks, http://stackoverflow.com/questions/3498211/asp-net-objectdatasource-error-handling asp.net error-handling share|improve this question asked Aug 16 '10 at 23:26 Eatdoku 2,224103575 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted Like this: protected void Page_Load(object sender, EventArgs e) { ds.Selected += new ObjectDataSourceStatusEventHandler(ds_Selected); } void ds_Selected(object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception != null) { } } share|improve this answer answered Aug 16 '10 at 23:31 Jeroen 3,34111331 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged asp.net error-handling or ask your own question. asked 6 years ago viewed 1025 times active 6 years ago Linked 1 Error handling in ObjectDataSource Related 0ASP.NET Error Handling Question2Simulating RemoteOnly custom errors using Application_Error ASP.NET3How to handle this error gracefully in asp.net?0Design Pattern for error handling in
August 2009 (1) June 2009 (2) May 2009 (2) April 2009 (2) Ariel Popovsky's Blog Aventuras y desventuras con .net << JQuery http://geekswithblogs.net/apopovsky/archive/2009/06/22/exceptionerror-handling-using-the-objectdatasource.aspx Autocomplete with WCF services | Home | Re-Installing Daemon Tools Lite https://bytes.com/topic/asp-net/answers/330972-objectdatasource-exception-handling (and SPTD) on Windows 7 >> Exception/Error handling using the ObjectDataSource Comments (3) | Share This post was going to be a rant about how using the ObjectDataSource was impossible to handle exceptions thrown while retrieving or updating data. After some experiments and reading some misleading posts I asp net saw only three possible ways: Use a generic error handler like the Page Error event or the Application Error event in global.asax. Implement handlers for the Updating, Selecting and Deleting events of the GridView bound to the datasource, set the event.Cancel to true and then manually call the Insert, Delete, Update and Select methods of the data source inside a asp net objectdatasource try/catch block. Throw away the data source and do everything manually. Luckily I accidentally found the right way to do it while looking at the EventArgs class properties for the Selected event. When the ObjectDataSource calls your data object, if the result is an exception it will call your post event event-handler (Selected, Deleted, etc). The EventArgs has two properties for managing exceptions, one is the Exception itself, the other is a boolean, ExceptionHandled. If you want to handle the exception you just need to set the ExceptionHandled property to true. 1: protected void MyDataSource_Deleted(object sender, ObjectDataSourceStatusEventArgs e) 2: { 3: if(e.Exception!=null) 4: { 5: ShowMessage(Constants.GenericErrorMessage, MessageType.Error); 6: e.ExceptionHandled = true; 7: } 8: else 9: { 10: ShowMessage("Entity deleted successfully.", MessageType.Success); 11: } 12: } Technorati Tags: ASP.net,ObjectDataSource,GridView Posted on Monday, June 22, 2009 10:54 AM ASP.net | Back to top Related Posts on Geeks With Blogs Matching Categories Angular - redirect to login after user session exp... ASP.Net Avoid ClickJacking in ASP.Net Core 1.0 ASP.Net Easy CRUD for Your Web API With Dapper asp.ne
your question and get tips & solutions from a community of 418,430 IT Pros & Developers. It's quick & easy. ObjectDataSource and Exception handling P: n/a nunya5200-bidness 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 Post Reply Share this Question 2 Replies P: n/a Brock Allen 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