FormView ModeChange Event Doesn't Fire

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
 
G

Guest

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.
 
G

Guest

Hi again Mark,

No because each template is independent so viewstates for different
templates do not interfere with each other.
 
G

Guest

Please forgive me, this reply should have gone to your first post 'Subject:
Limitation of FormView Control?' :)
 
M

mark

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top