Hi all,
I noticed in the SDK that there's a class called PageValidateEventArgs. Can this be used in any way to enforce custom validation when saving a page?
When a page of a certain page type is saved, we would like to abort the save and show a nice custom error message (in the same way as error messages are displayed when a mandatory property is not filled in) to the user, if a certain combination of property values are entered. Would this be possible to do in EPiServer CMS?
Thanks,
Christoffer
Hi Christoffer!
Take a look on the class EPiServer.GlobalPageValidation. This class has an event handler called Validators that you can use to attach your own validation handler that will be triggered when trying to save a page. An example:
protected void Application_Start(Object sender, EventArgs e)
{
GlobalPageValidation.Validators += new PageValidateEventHandler(GlobalPageValidation_Validators);
}
protected void GlobalPageValidation_Validators(object sender, PageValidateEventArgs e)
{
if(e.Page.PageName.Length <= 5 && e.)
{
e.ErrorMessage = "Page name must have at least 6 characters.";
e.IsValid = false;
}
}