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.
--
Milosz
"Mark Olbert" wrote:
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