Click here to Skip to main content
6,594,932 members and growing! (17,653 online)
Email Password   helpLost your password?
Enterprise Systems » SharePoint Server » General     Beginner License: The Code Project Open License (CPOL)

Adding Validation to a Custom List Control in Sharepoint

By Rajan Bhanot

Validation can be achieved from inside the Sharepoint designer
Architect, Dev, Design
Version:2 (See All)
Posted:29 Jul 2008
Views:20,524
Bookmarked:14 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
3 votes for this article.
Popularity: 2.15 Rating: 4.50 out of 5

1

2
1 vote, 33.3%
3

4
2 votes, 66.7%
5

Introduction

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.

Background

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:

    072908_0945_Addingvalid1.png

  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:

    072908_0945_Addingvalid2.png

  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:

    072908_0945_Addingvalid3.png

  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).

    072908_0945_Addingvalid4.png

  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.

    072908_0945_Addingvalid5.png

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

    072908_0945_Addingvalid6.png

  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:

    072908_0945_Addingvalid7.png

  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.

    072908_0945_Addingvalid8.png

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

    072908_0945_Addingvalid9.png

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

    072908_0945_Addingvalid10.png

  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:

    072908_0945_Addingvalid11.png

  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:

    072908_0945_Addingvalid12.png

Happy Sharepointing…

History

  • 29th July, 2008: Initial post 

License

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

About the Author

Rajan Bhanot


Member
Rajan Thakur is a Senior MS Solutions Consultant, working with SharePoint 2007 and .net for over 6 years now.

Email: rajan_thakur78@yahoo.com
Occupation: Software Developer (Senior)
Company: Capgemini
Location: India India

Other popular SharePoint Server articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
QuestionHow to do "Required field" validation like a SharePoint:FormField? Pinmembermatturn15:56 16 Jul '09  
GeneralValidation not working for US Phone number PinmemberMember 166258120:23 9 Apr '09  
GeneralProblem Pinmemberredmondscorpio9:06 27 Jan '09  
QuestionHow about cross validation PinmemberSingh_h10:24 19 Jan '09  
Questionhow to do achieve same objective using C# code PinmemberMember 421240723:48 26 Nov '08  
QuestionDoes this method work on Edit form also? Pinmembersandeep Kumtakar22:48 3 Nov '08  
QuestionControl 'ff11_1' referenced by the ControlToValidate property of 'RequiredFieldValidator1' cannot be validated PinmemberBrianVen3:05 3 Nov '08  
QuestionUnable to add validations Pinmemberkalpana.tulla23:47 31 Aug '08  
AnswerRe: Unable to add validations PinmemberRajan Bhanot0:20 1 Sep '08  
AnswerRe: Unable to add validations Pinmembermadhu.sen.in23:31 27 Aug '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Jul 2008
Editor: Deeksha Shenoy
Copyright 2008 by Rajan Bhanot
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project