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
Post a Comment