Monday, 26 August 2013

SPContext.Current.FormContext.OnSaveHandler Not Firing from Custom Field Type Control

SPContext.Current.FormContext.OnSaveHandler Not Firing from Custom Field
Type Control

I am having the exact same problem described here. Unfortunately because I
don't have 50 points yet I can't comment on it so I have to create a new
duplicate question.
I mean it's not "100% EXACTLY" like the other guy's problem because for me
the problem exists on the Edit Form and I'm using a combination of custom
forms and fields. But I am adding the custom save event handler at the
field level per suggestion #2 made by the guy at this site. I should also
note that when I create a new Document Library without any custom forms
and just use my custom fields straight-up, the event handler DOES fire. So
I'm not quite sure why it doesn't work in my customized Document Library
because I was under the assumption that the beauty of custom fields was
that they operate independently of everything else. Meaning, even if I was
doing something wonky with my Edit Form or some other control, since I am
attaching my custom method to the
SPContext.Current.FormContext.OnSaveHandler in the OnInit method of my
custom field then that should fire no matter what! Even when the field is
being loaded for the first time I actually see the event being wired up in
the debugger. In debug mode I have a breakpoint next to the "if" statement
below and it hits that breakpoint which means that when the
FormContext.OnSaveHandler is triggered my method should fire.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if ((SPContext.Current.FormContext.FormMode == SPControlMode.New) ||
(SPContext.Current.FormContext.FormMode == SPControlMode.Edit))
SPContext.Current.FormContext.OnSaveHandler += new
EventHandler(MyHandler);
}
Any thoughts? Suggestions?
Thanks!

No comments:

Post a Comment