Sharing the experience search

Search sharing-the-experience.blogspot.com

Wednesday, November 17, 2010

SaveButton: Double postback while validating

A quick note - it's been seen several postbacks while submitting a form. The reason - Microsoft.SharePoint.WebControls.SaveButton which has a  method:
protected override bool OnBubbleEvent(object source, EventArgs e) {
and the following code is present -  this.Page.Validate();
Seems normal.....but the SaveButton contol has  a contol button within itself - internal Button ButtonControl
 which in his turn has a method:protected virtual void RaisePostBackEvent(string eventArgument)
and what  a surprise! the method executes  this.Page.Validate(this.ValidationGroup);

Since the Save Button generates 2 Page.Validate(), the postback appears twice during saving.
It's not only annoying but kind of killing the performance.
So if you want to fix it - you can do it fast:
just implement on you custom code Page -
  public override void Validate()
        {
            if (!_validationCompleted)
            {
                base.Validate();
                _validationCompleted = true;
            }
        }

No comments:

Post a Comment