FormView ModeChange Event Doesn't Fire

  • Thread starter Thread starter Mark Olbert
  • Start date Start date
M

Mark Olbert

I'm trying to understand how to respond to mode changing events in a FormView control. I'm not using datasource controls, so I have
to do more of the plumbing myself.

Do I have to call the ChangeMode() method in the ModeChanging event handler?

Why doesn't the ModeChanged event fire? I can see the mode in the process of changing, because my ModeChanging handler gets called,
but then the ModeChanged handler never gets called.

- Mark
 
Hi Mark,

I had a look at the FormView control's code, and it seems ModeChanged event
is only raised when formview is bound to a datasource control (i.e.
sqldatasource, objedatasource etc). See it for yourself:

private void HandleNew()
{
FormViewModeEventArgs args1 = new
FormViewModeEventArgs(FormViewMode.Insert, false);
this.OnModeChanging(args1);
if (!args1.Cancel)
{
if (base.IsBoundUsingDataSourceID)
{
this.Mode = args1.NewMode;
this.OnModeChanged(EventArgs.Empty);
}
base.RequiresDataBinding = true;
}
}

Unfortunatelly, you have to handle ModeChanging event and call ChangeMode()
manually with e.NewMode argument:

protected void fv_ModeChanging(object sender, FormViewModeEventArgs e)
{

fv.ChangeMode(e.NewMode);
// rebind the data
fv.DataSource = anyDataSource;
fv.DataBind();
}

Done.
 
Hi again Mark,

No because each template is independent so viewstates for different
templates do not interfere with each other.
 
Please forgive me, this reply should have gone to your first post 'Subject:
Limitation of FormView Control?' :-)
 
Milosz,

Thanks for the quick reply. I didn't think to check whether
ModeChanged was only called when using a DataSourceID-object. I don't
generally use DataSourceID-type objects, preferring a more "explicit"
style of data binding.

- Mark
 
Back
Top