Client-side validation

I’m having some “fun” with client-side validation on a roll-my-own BaseValidator subclass.

My validator is to validate email format and includes the following code (with XMLdoc removed for brevity):

using System;
using System.Text.RegularExpressions;

namespace IrisDigital.WebControls.Validation
   public class EmailValidator : BaseValidator
      protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)

         if (base.RenderUplevel)
            writer.AddAttribute("evaluationfunction", "CheckEmailFormat");
            writer.AddAttribute("controltovalidate", this.GetControlRenderID(this.ControlToValidate));

      protected override bool EvaluateIsValid()
         // ...

      protected override void OnPreRender(EventArgs e)

         if (base.RenderUplevel)
            if (!Page.ClientScript.IsClientScriptBlockRegistered("IrisDigital.WebControls.Validation.EmailValidator"))
                  Page.ClientScript.GetWebResourceUrl(this.GetType(), "IrisDigital.WebControls.Validation.EmailValidator.js"));
            this.ClientValidationFunction = "CheckEmailFormat";

Most of the rationale for doing things this way is from an article on CodeProject: RequiredIfValidator — Extending from the BaseValidator class, which does it precisely this way.

The validator works wonderfully. But the client-side validation never fires.

The WebResource correctly gets added to the page as a script include (for which I need to have the following line in my AssemblyInfo.cs, in case you were wondering):

[assembly: System.Web.UI.WebResource("IrisDigital.WebControls.Validation.EmailValidator.js", "text/javascript")]

, but it just never gets called.

Anyone got any ideas why?

Cross-posted to csharp and ms_dot_net.



Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s