Try our conversational search powered by Generative AI!

Custom validation before saving a page

Vote:
 
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
#15811
Oct 04, 2007 15:38
Vote:
 
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; } }
#16416
Oct 05, 2007 14:08
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.