More in this section

Forums / Developing with Sitefinity / Inheriting FormsControl - how can I add custom validation

Inheriting FormsControl - how can I add custom validation

2 posts, 0 answered
  1. Ryan
    Ryan avatar
    57 posts
    07 May 2013
    30 Jan 2014
    Link to this post
    I have a specific form I have developed that inherits from the standard FormsControl. I need to be able to add an error message to the screen if custom condition of mine fails when submitted. This type of validation falls outside of what I can configure within the back-end, as it requires a web service call prior to submission.

    How can I simply add an error message to the UI? Is there a collection of errors that I can append to, that, if any exist, will invalidate the form? Thanks.
  2. Vassil Vassilev
     Vassil Vassilev avatar
    308 posts
    21 Jan 2015
    04 Feb 2014
    Link to this post
    Hello Ryan,

    There is a blogpost which will help you achieve your requirement:

    What you seek is the following:
    base.BeforeFormSave += new EventHandler<CancelEventArgs>(this.FormsControlCustom_BeforeFormSave);

    By attaching to this event you could perform your validation and if the validation fails to call "e.Cancel = true;" which will cancel the form submission. At the end of this blogpost you can find a sample code which with only small modification will do the job for you.

    Vassil Vassilev
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered