Sunday, March 1, 2009

ValidationGroup in SharePoint 2007

The situation

You have an ASP.NET control that contains validation controls in the masterpage or page layout for a publishing site (an ASP.NET login control for example). When you try to edit and check in a publishing page you receive the following error.
This page contains content or formatting that is not valid. You can find more information in the affected sections.

The problem
Even if you fill in all the required fields on the publishing page, the validation controls on the other ASP.NET controls prevent the page from saving.

The solution:
You have 2 solutions:
1. Put your control in EditModePanel
<PublishingWebControls:EditModePanel runat=server id="EditModePanel1" PageDisplayMode="Display">
<------------Your Control --------------->
</PublishingWebControls:EditModePanel>

2. Hide your validators in edit mode:
WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page);
if(wp.DisplayMode == WebPartManager.BrowseDisplayMode)
{
yourvalidator.Visible = true;
}
else
{
yourvalidator.Visible = false;
}

No comments: