Skip to main content

Adding validation to a custom list control in Sharepoint

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 Wizard will ask to choose a List or Document Library form on based Of existing list. Choose your Validation list and select New item form under type of from 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 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 .
  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 IE and try to type in invalid email id and you will get following .

Comments

Popular posts from this blog

Sharepoint Interview questions

What is Microsoft Windows SharePoint Services? How is it related to Microsoft Office SharePoint Server 2007? Windows SharePoint Services is the solution that enables you to create Web sites for information sharing and document collaboration. Windows SharePoint Services -- a key piece of the information worker infrastructure delivered in Microsoft Windows Server 2003 -- provides additional functionality to the Microsoft Office system and other desktop applications, and it serves as a platform for application development. Office SharePoint Server 2007 builds on top of Windows SharePoint Services 3.0 to provide additional capabilities including collaboration, portal, search, enterprise content management, business process and forms, and business intelligence. What is Microsoft SharePoint Portal Server? SharePoint Portal Server is a portal server that connects people, teams, and knowledge across business processes. SharePoint Portal Server integrates information from various systems into o

SharePoint 2010 Branding: Change site actions and welcome menu arrows

Here's how you can do it. Hide the image and give our custom image element a background image. Look Like: .ms-viewselector-arrow {     background: transparent url('/PublishingImages/images/Arrow.png') no-repeat scroll 0 0;     height: 4px; /* height of the image */     width: 5px; /* width of the image */ } .ms-viewselector-arrow img {     display: none; }

Lookup field does not showing values in sharepoint2013

SharePoint Custom Form Shows HTML as Text on Lookup Fields   When creating a custom display form on SharePoint Designer, the form displays the actual HTML instead of rendering the HTML on the lookup columns. For example, see the below image: For the lookup value issue, you need to slightly modify the XSLT of the particular field from designer and add the attribute disable-output-escaping="yes" to the field.