ASP.Net Validators in SharePoint

  • Posted by: Softree Technology

commands1

There are times when emerge the requirements of adding various client side validations on the web pages. Perquisite is there is an easy way to do this in ASP.Net by the utilizing the existing set of validator controls.

When we design custom webparts in SharePoint, not to mention it takes some data as input, in that way we have to Asp.Net to add some client side validation. However, there are few things that you ought to keep in mind while using Asp.Net validator controls in the on board with SharePoint.

  • There may be more than one control you will find, that trigger server side postbacks. If this is the case the validator controls will validate individually with each postback. However, the requirement may vary some times and you might have validate the form with single postback event, for instance through the “SUBMIT” button. In order to steer clear of this situation, you must put “Causes Validation property” to false. You need to do the same for all the controls causing server side postbacks OR for all those postbacks for which you do not want the form to get validated. (e.g.CausesValidation=”false”)
  • As mentioned in our previous article , SharePoint page facilitates multiple webparts. Therefore, if the one of the webparts is being integrated with ASP.Net validator, it will always create issues with the postback events along with the page that contains other webparts. To steer clear of this issue and confine the validation to a particular webpart, you have to use ValidationGroupProperty within a specific webpart with a unique name.

e.g. ValidationGroup=”UniqueGroupName”

  • If you are following all the above facts and thinking everything is done then stop… there is still a problem which needs to be sorted out in SharePoint. When there is ASP.Net validator integrated within a webpart, webpart properties wouldn’t allow you to save the changes due to the validators, no matter if the with ValidationGroups set. To fix this go to the webpart and find Form Mode within the Page Load event then disable the ASP.Net validator controls while the form is in “NEW”or “EDIT” mode.

e.g.

* If SPContext.Current.FormContext.FormMode = SPControlMode.Edit

* Or SPContext.Current.FormContext.FormMode = SPControlMode.New Then

* ‘Set the visibility of the required field control to False

* End If

Softree Consulting employs SharePoint consultants, who are experienced in writing for a multiplicity of SharePoint verticals including technical, promotional, creative, branding content, cataloguing and ethical media comprising journalism.

With more than 10 years of industry experience these professionals have the best resources to deliver optimum results. They have been satisfying customers with some of the best SharePoint Strategies. In case you need experts for Offshore development for SharePoint 2016, we have got you covered.

 

Author: Softree Technology

Leave a Reply