Let's say I have a page with FormView where there is a form allowing to register article into database. User can fill some properties like Number, Description etc. I use EntityDataSource.
I can perform insert/update operations. The problem is that in some cases (exactly if IsDeleted property of the object with the same Number is set to true) I want to cancell Insert operation and perform Update instead. To do so I started with such thing:
protected void ArticleFormView_ItemInserting( object sender, FormViewInsertEventArgs e )
{
string articleNo = e.Values[ "Number" ].ToString();
// ...some other things...
if ( this.ShouldUpdateInsteadOfInsert( articleNo ) )
{
e.Cancel = true; //cancel insert
this.ArticleFormView.ChangeMode( FormViewMode.Edit );
this.ArticleFormView.UpdateItem( false );
return;
}
}
This successfully cancels Insert and invokes Update. However in the ArticleFormView_ItemUpdating event handler property NewValues of FormViewUpdateEventArgs object has some default values - not the ones entered by user.
protected void ArticleFormView_ItemUpdating( object sender, FormViewUpdateEventArgs e )
{
// e.NewValues["Number"] - not the same as
// e.Values["Number"] from ArticleFormView_ItemInserting
}
Is there a possibility to make it work this way?
I could manually create an Entity object in ItemInserting and assign all values manually, but object has 200+ fields so I'm looking for a better approach.
I'll apreciate any good solution for this case.
Still, if anyone knows a better solution, please respond.
I managed to write a code that maps the values using reflection. I do not invoke
Updatemethod, but I perform a database update manually inItemInserting.