Error handling with a custom field control - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Error handling with a custom field control

  • Error handling with a custom field control
  • a123551e-37c1-6deb-a958-ff0000446526_sf_widget_issue.jpg

    I’m working in Sitefinity 9.1 and I’m trying to implement Googles reCAPTCHA 2.0 ( as a field control widget in Sitefinity. In the Global.asax.cs file, I’ve subscribed to the IFormsModuleEvent:

    if (e.CommandName == "Bootstrapped")
        EventHub.Subscribe<IFormsModuleEvent>(evt => reCaptcha.reCaptcha_FormSavingEventHandler(evt));

    Then, in the widget, I implemented the reCaptcha_FormSavingEventHandler: 

    public static void reCaptcha_FormSavingEventHandler(IFormsModuleEvent evt)
        if (evt is FormValidatingEvent)
            string reCaptchaResponse = SystemManager.CurrentHttpContext.Request.Form.GetValues("g-recaptcha-response").First();
            ReCaptchaResponse validatorResponse = ReCaptchaValidation.Validate(reCaptchaResponse);
            if (!validatorResponse.success)
                throw new ValidationException(validatorResponse.errorCodes.First());

    For good measure, here is my template:

    <%@ Control %>
    <%@ Register Assembly="Telerik.Sitefinity" TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" %>
    <script src="" async defer></script>
    <div id="gCaptcha" runat="server" class="g-recaptcha" data-sitekey="xxx"></div>


    I’m stuck on how to get the error message to display where the widget is located. The error does display at the top of the form (highlighted in attachment), which is undesirable. I’d like it to appear below the widget itself. There isn't much else going on in the class, just logic for the template and script files (I'm not doing anything in the .js file; no client side validation and no data to store and/or retrieve).

    Does anyone have any ideas on how to accomplish this?