Wednesday, April 7, 2010

Validation control prevent page from saving on SharePoint

If you have a web part containing some validation controls, when you Edit Page->Modify Shared Web Part->Save, the validation controls would prevent page being saved. You need fill all fields to complete the operation. There are two solution:

  1. Check the SPContext.Current.FormContext.FormMode == SPControlMode.Edit in you code, when the page mode is Edit, you can disable the validation controls. But there is still  a problem for this solution, if you Edit Page->Modify Shared Web Part->Save, then everything is fine. But if you Modify Shared Web Part->Save, the validation controls still work.
  2. The best method is using the ValidationGroup property. You can assign the your Validator controls and the controls that would trigger validation a same validation group name.Validation groups allow you to assign validation controls on a page to a specific category. Each validation group can be validated independently of other validation groups on the page. Use the ValidationGroup property to specify the name of the validation group for which the Button control causes validation when it posts back to the server.
  3. The third solution is not mine. I have not tried it yet. You can refer it

No comments:

Post a Comment