h1

e.Cancel and update page

October 30, 2008

First at all I solved this f***ng problem than I found this forum.  My problem was, that I used FomView default setted to FormViewMode.Edit.  If I changed mode to Insert mode ,calling FomView.CahngeMode(FormViewMode.Insert), than  it worked fine. However I made mistake in FormView (bad typed price etc…) I validated data on server . After bad validation which I made in Inserting handled method of Object DataSource I called called e.Cancel.

It’s good idea but  result is, that updating of page is stopped => FormView will be setted to Edit mode, not to in insert Mode (prepared to pass data about new customer again). My solution of this is to set flag and set values of components in overrided prerender method.

 

//method blocks processing of updating page
private
void BlockCommandProcessing(ObjectDataSourceMethodEventArgs e, string message)
{
 
OnError(message);
 
e.Cancel = true;
 
_formviewWillBeVisibleAndInInsertMode = true;
}

//is setted when e.Cancel is called => we lost settings of page
//I will set it again in prerender phase
private bool _formviewWillBeVisibleAndInInsertMode;

protected
override void OnPreRender(EventArgs e)
{
if (_formviewWillBeVisibleAndInInsertMode)
    SetVisibilityOfItems(ControlStates.InsertClicked);
base.OnPreRender(e);
}

SetVisibility method sets FormView mode and visibilities of controls in depends of ControlState.

 

Links

 

 

Leave a Comment