Prevent field validators from firing when editing a web part

I have a simple visual web part with a RequiredFieldValidator. The only problem is that when the web part properties are set, a postback is fired and the validator is complaining. The net result is that I cannot make any configuration changes to the web part.

The following code will resolve this problem:

    protected override void OnPreRender(EventArgs e)
        {
            WebPartManager mgr = WebPartManager.GetCurrentWebPartManager(Page);
            if (mgr.DisplayMode.Equals(mgr.SupportedDisplayModes["Browse"]))
            {
                myValidator.Enabled = true;
            }
            else
            {
                myValidator.Enabled = false;
            }

            base.OnPreRender(e);
        }

Comments

Popular posts from this blog

SharePoint 2013: Error updating managed account credentials

Error deploying Nintex workflow: An item with the same key has already been added