Skip to main content

PublishingLayoutPage: Server side validation for the pages and the use of RaisePostBack event.

Recently i got a chance to learn about a new SharePoint class PublishingLayoutPage and the importance of RaisePostBack Event. RaisePostBack event is raised for any ribbon actions like edit,save, publish etc. The main advantage of this is we can override this class for doing server side validation or updating of the hidden fields based on the user input. Let me explain this with an example.

Scenario:- I have a pages library for storing the news article pages. Validation must be happen only when a check box field is selected.

Implementation:


  • Design a news page layout with all the fields that needs to be shown.(I don't want to go into details of how to design a page layout).
  • Create a new class and inherit the PublishingLayoutPage class as shown below.
Page layout class
  •  Override the RaisePostBack Event and Validate method as shown above. 
  • In the validate method check whether field is checked or not and do the validation. if the field is not valid change the field isValid property to false as shown below. We can also set the error message using the ErrorMessage property.
Validate Method class
  • In the RaisePostBack event make a managed metadata field mandatory as shown below. 
RaisePostBack event method
  • There are different eventArgument values based on the ribbon action. the string values are given in the below link.
                 https://msdn.microsoft.com/en-us/library/ee556269(v=office.14).aspx 
  • Go to your page layout and overwrite the page directive as shown below.
Replacing the page directive.
  • That completes the setting up of the server side page validation for the page layouts. 
Hope this is helpful for someone.



Comments

Popular posts from this blog

How to upgrade typescript version in a SPFX solution

Why do we need to upgrade typescript version in a SPFX solution? As part of SPFX development we try to install 3 rd party libraries, there is a possibility that we might face type errors. For example, if we try to install ANTD package as part of your solution and use one of its components and try to build the solution. You might be seeing the type errors (TS1005,TS1109) as shown below. Typescript errors How to find out the typescript version? When you build (Gulp build) the SPFX solution you will be able to find out the typescript version from the build log as shown below.  Steps for updating the Typescript version. In SPFX solution typescript version has dependency on the @Microsoft/rush-stack-compiler package version.  In the package.json if you have @microsoft/rush-stack-compiler-2.7 then the typescript version is 2.7.x.    In the SPFX solution deleted the node_modules folder. It will remove all the packages that are installed....

Microsoft Graph API and SharePoint

While developing solutions for office 365 Microsoft graph API will help you in achieving the required output. In my previous project where I have used Graph API, I found it difficult for getting info on some of the endpoints. Below I will try to list out some of the basic and most used end points of Microsoft graph API for SharePoint. Getting site level information Searching for Sites https://graph.microsoft.com/v1.0/sites?search=* it returns the list of site collections the user have permission. Site details based on the relative path https://graph.microsoft.com/v1.0/sites/{host-name}:/{server-relative-path} if the site collection url is https://contoso.sharepoint.com/sites/test1 Host-name:- contoso.sharepoint.com Server relative path:- sites/test1 Graph Url:- https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/test1 Different ways to get list data Get the list data for a root site https://graph.microsoft.com/v1.0/sites/root/...

Use of Expression in Microsoft flow through an example

Most of the basic flows can be configured using the templates provided by Microsoft. But in real time we will be developing flows which have complexity. Expression play an important role in fulfilling the requirements. Scenario : -  We have project details list which has the below columns, we need to intimate the project team before 2 days of the end date. (Please note that this scenario is picked up from one of the Microsoft insight demo) The following points needs to be implemented ·          Only title and End time are mandatory fields, Start time if not entered needs to be taken as the current date. ·          Number of days is the difference between the start time and end time.   ·          Email needs to be sent before 2 days of the end date. ·          If any attachments they nee...