I decided to use DI mechanism to implement validation but have run in to the follwing problem :
When the user tries to do an update, and the update fails validation, the control (e.g. details view) remains in edit mode which is good but all the user changes have been lost. Instead the original values are displayed.
How do I continue to show the changed values after a failed validation?
Here is how I am doing validation:
I am using LLBLGen datasource.
I set the filter for the datasource in the page load only if its not a post back.
I am using DI (auto discovery) to do some validation and throw an error. e.g. throw new ORMEntityValidationException(strExceptionMessage, toValidate);
My issue is : When updating a record, say it fails validation. The details view control stays in edit mode as expected but the values have reverted back to the original values and so the user has lost all her changes even though only one field might have failed validation.
The reason the original values are restored is I think, the PerformSelect event is fired and the llblgen datasource has got the original values.
I do not want the edited values lost unless the user cancels the edit. How do I achieve this?
Here are the events I am using :
Note : dvAddress is the name of the asp details view control.
ldsAddress is the name of the llblgen datasource instance.
protected void dvAddress_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
// if there is errors, cancel the DetailsView mode change, so the user could fix the values
if (blAddressErrors.Visible && !e.CancelingEdit)
{
e.Cancel = true;
}
// if the user is canceling, hide the control that show the errors.
if (e.CancelingEdit)
{
HideEntityErrorControls();
}
}
protected void ldsAddress_PerformWork(object sender, PerformWorkEventArgs e)
{
try
{
using (Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "PerformWork"))
{
e.Uow.Commit(trans, true);
}
// no errors, so hide the errors.
HideEntityErrorControls();
}
// some validation rules have been broken!
catch (ORMEntityValidationException ex)
{
// Show entity errors to the user.
ShowEntityErrors(ex.Message);
}
}
protected void ldsAddress_PerformSelect(object sender, PerformSelectEventArgs e)
{
e.ContainedCollection.GetMulti(e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter,
e.Relations, e.PrefetchPath, e.PageNumber, e.PageSize);
}
I am using LLBLGen 2.5 Final, self servicing 2 class templates. ASP.NET 2.0.