Gridview rowupdating error handling
As our code does not handle those events hence they throw an exception.
So when we change the Command Name property of the buttons to some other text then it will work fine.
I'm using an Object Data Source and some data are validated in business object.
But the instance of the business object is created just when inserting by the Object Data Source (the instance is not available in Row Validating or Row Inserting event handler).
Custom Error Text event not raised in non-callback scenarios? If it is not a bug, is there any workaround other than using Row Validating or Row Inserting events? Custom Error Text event is not raised when postbacks are used. NET nature when it is not possible to determine how an exception should be processed. NET destroys the processed page, and you cannot know where the error string should be displayed (the grid does not exist, and the error row does not exist as well) on the server side.
The only solution is to handle the Application_Error event where you can try to change something, or log the exception somewhere.
If it does not help you to understand my problem, I could prepare an isolated project demonstrating this issue over standard Sql Data Source. Hello Jan, When you handle an exception as mentioned in the first post, this means that the ASPx Grid View thinks that everything is fine and closes the edit form.
That is why you should not handle the exception at all, if you want to format an error message the ASPx Grid View. According to your exception stack trace, I see that you are trying to insert an object to a database with an existing primary key.
So my final question is - why is the ASPx Grid View. I understand your approach, and I am sorry to admit that the ASPx Grid View.
There is a very simple validation business rule: the record should have filled either Person Name or Company Name.
(I know that this rule can be implemented in the Row Inserting event, but there are more complex rules that is not easy to implement there) When the rule is violates, inserting of new ASPx Grid View row fails with unhandled exception.
The simplest solutions for this error is : Just change the “Command Name” property of the “Edit” button from “Edit” to “Edit Row”(or something else which is relevent to you but make sure it is not “Edit”). After scratching my head for sometime I found that the words like “Edit” are reserved to invoke some built in functionality of the Grid View.
So when we use these special key words as the Command Name for the buttons in the Grid View, they automatically invoke the built in functionality of the Grid View when we click on the button.