by Andreas

Sharepoint 2010 – disable client side validation while in edit mode

If your web part uses client side validation you would have experienced how annoying this is when opening the page in Edit Mode. I knew there had to be a way to turn this off, but it wasn’t until today I actually spent a few minutes figuring it out. The solution is to add an IF statement in the Page_PreRender() method to check the current page mode, and then disable the client side script for the validation controls:

protected void Page_PreRender(object sender, EventArgs e)
    // determine if page is in Edit mode
    WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page);
    if (wp.DisplayMode == WebPartManager.EditDisplayMode)
        // disable all client side validation
        RequiredFieldValidator1.EnableClientScript = false;
        RequiredFieldValidator2.EnableClientScript = false;
        ValidationSummary1.EnableClientScript = false;