Tuesday, July 6, 2010

Disable WebPart form validators when page is in edit mode

There was a issue that my form validators gets fired when we are in Page edit mode or we are updating a webpart.

So we need to disable validators when page in in edit mode.

Solution

On WebPart user control

using Microsoft.SharePoint.WebPartPages;

protected void Page_Load(object sender, EventArgs e)
{
if (SPWebPartManager.GetCurrentWebPartManager(Page).DisplayMode != WebPartManager.BrowseDisplayMode)
validator.Enabled = false;
}

No comments: