I have a property with XHTML data type. In that iam placing some links. If the placed links are not correct (broken links) then after pressing the publish button i want to show the user with appropariate comments and want to cancel the publishing action.
Can you please suggest how to achieve this kind of functionality.
Thanks in advance.
There are two options for this if you are refering to EPiServer CMS 5/6 properties. Either you create an override of the ApplyEditChanges method and validate the input data directly. If the data is invalid you can call the AddErrorValidation(string errorMessage) method which will display the error message and cancel the action (publish/save etc). This option will only validate data that is entered through properties, for instance when editing a page.
Option two is to apply the validation in the Property class, for instance in the Value property. If the data is not valid you throw an exception with the validation error message. This error message will then be catched when saving the page and shown to the user. Note that a validation at this level will affect more than just editing a page, for instance when importing pages. This might hinder import of a package for another system that does not have the same validation.
So, if you really want to validate that data that does not fit your criteria never enters the system, then add the validation at property level. If you just want to make sure that editors does not enter invalid data but accept that imported data might include "invalid" data you should instead add the validation at property control level.
RegardsLinus EkströmEPiServer Development Team