Click here to Skip to main content
13,397,903 members (48,279 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 29 Jul 2008

Adding Validation to a Custom List Control in Sharepoint

, 29 Jul 2008
Rate this:
Please Sign up or sign in to vote.
Validation can be achieved from inside the Sharepoint designer


Recently, one of the requirements was to put validation to a custom list control such as Email field validation.

This validation can be achieved from inside the Sharepoint designer.

Following is a step by step walkthrough to validate a list field.


You should know how to create a Sharepoint list and how to open the site in Sharepoint designer.

  1. Following is a list with Email fields. Let's say we have to validate so that only a valid email can be entered.

    If not valid, then the Error Message appears next to the field:


  2. Now open the site in the Sharepoint designer and then expand the list and open the Newform.aspx of the list to be validated:


  3. As you can see in the image above, the Newform.aspx of Validation list is being opened in the Sharepoint designer.

  4. Now right click on this Validation list Web part in Sharepoint designer and choose Web Part properties:


  5. The properties dialog box will open for the Validation list here. Choose Hidden under layout and say OK.

    (This web part can be deleted as well, but due to some known problems because of deletion, it is best to hide this).


  6. Now click exactly underneath the hidden list web part and go to Insert->Sharepoint Controls-> Custom List Form… and the Wizard will ask to choose a List or Document Library form based on existing list.
    Choose your Validation list and select New item form under type of form to create option and hit Ok.


  7. You will get the Validation List underneath the hidden list as shown as selected image below:


  8. Now from here, we can customize all the controls based on requirement. As we are customizing the E-Mail field, right click on the email field box and choose Show common control tasks from the context menu:


  9. This will give you Common Formfield tasks option as shown below next to the Email field. Here we can change the format of the data field selected (default is List form field). As we need Email field to be textbox where validation can be applied, Choose Textbox from Format as dropdown instead of List form field.


  10. After the above step, List will look like this (custom formatted):


  11. Now drop a RegularExpressionValidator control from the Validation option under ASP.NET controls from the toolbar as shown below:


  12. Now specify the required properties (such as ControlToValidate, ErrorMessage, SetFocusOnError to true, Validate Expression) of the RegularExpressionValidator from the Tag Properties toolbar. For ControlToValidate, choose the ID of the Email field.

    After selecting it and getting the ID from the Tag Properties toolbar as you do in Visual Studio, see below the set attributes in blue for the Email field:


  13. Now, save the changes and go back to the list in Internet Explorer and try to type in an invalid email id and you will get the following:


Happy Sharepointing…


  • 29th July, 2008: Initial post 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rajan Bhanot
Software Developer (Senior) Capgemini
India India
Rajan Thakur is a Senior MS Solutions Consultant, working with SharePoint 2007 and .net for over 6 years now.


You may also be interested in...


Comments and Discussions

QuestionRequiredField validator produces an unexpected error has occured error... Pin
rdkll2k8-Nov-11 10:49
memberrdkll2k8-Nov-11 10:49 
When I attempt to add the requiredfield control to a SharePoint 2007 custom form connected to a list attempting to require a selection in a lookup field populated drop down list I receive the "an unexpected error has occured" error. Unfortunately there are no further details provided.

I'm guessing that it has something to do with the controltovalidate value but I've tried the SharePoint:FormField id of ff1{$Pos} and a number of other variations with no success. Maybe I'm missing something else altogether.

I know that the form works without the validator because as soon as I delete it from the page it loads just fine.

Any ideas?

Questionhow to validate DropDownMenu? Pin
Abdullah_m27-Jun-10 22:48
memberAbdullah_m27-Jun-10 22:48 
QuestionHow to do "Required field" validation like a SharePoint:FormField? Pin
matturn16-Jul-09 15:56
membermatturn16-Jul-09 15:56 
GeneralValidation not working for US Phone number Pin
Member 16625819-Apr-09 20:23
memberMember 16625819-Apr-09 20:23 
GeneralRe: Validation not working for US Phone number Pin
bdimitre9-Feb-10 5:33
memberbdimitre9-Feb-10 5:33 
GeneralProblem Pin
redmondscorpio27-Jan-09 9:06
memberredmondscorpio27-Jan-09 9:06 
QuestionHow about cross validation Pin
Singh_h19-Jan-09 10:24
memberSingh_h19-Jan-09 10:24 
Questionhow to do achieve same objective using C# code Pin
Member 421240726-Nov-08 23:48
memberMember 421240726-Nov-08 23:48 
QuestionDoes this method work on Edit form also? Pin
sandeep Kumtakar3-Nov-08 22:48
membersandeep Kumtakar3-Nov-08 22:48 
QuestionControl 'ff11_1' referenced by the ControlToValidate property of 'RequiredFieldValidator1' cannot be validated Pin
BrianVen3-Nov-08 3:05
memberBrianVen3-Nov-08 3:05 
AnswerRe: Control 'ff11_1' referenced by the ControlToValidate property of 'RequiredFieldValidator1' cannot be validated Pin
wongm317-Feb-10 9:39
memberwongm317-Feb-10 9:39 
QuestionUnable to add validations Pin
kalpana.tulla31-Aug-08 23:47
memberkalpana.tulla31-Aug-08 23:47 
AnswerRe: Unable to add validations Pin
Rajan Bhanot1-Sep-08 0:20
memberRajan Bhanot1-Sep-08 0:20 
AnswerRe: Unable to add validations Pin
madhu.sen.in27-Aug-09 23:31
membermadhu.sen.in27-Aug-09 23:31 
GeneralRe: Unable to add validations Pin
wongm317-Feb-10 9:40
memberwongm317-Feb-10 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180216.1 | Last Updated 29 Jul 2008
Article Copyright 2008 by Rajan Bhanot
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid