Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I too have had this problem. After spending way too much time dissecting the MS client side validation API ;), I traced the problem to a weird issue with DOM parsing, below I explain why this happens in some cases and the solution I used to fix it. </p> <p><strong>[Why does it happen?]</strong></p> <p>Each validator control is rendered as a span with non-standard attributes that are used to perform the client side validation. For example the evaluationfunction attribute below:</p> <pre><code>&lt;span id="...id" controltovalidate="...BillingName" errormessage="blah" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" display="Dynamic" initialvalue="" &gt;*&lt;/span&gt; </code></pre> <p>These attributes are parsed by the framework in the API like this below (notice the eval):</p> <pre><code>for (i = 0; i &lt; Page_Validators.length; i++) { val = Page_Validators[i]; if (typeof(val.evaluationfunction) == "string") { eval("val.evaluationfunction = " + val.evaluationfunction + ";"); } } </code></pre> <p>the problem is that the special attributes i.e. evaluationfunction we're always returning undefined so the string was never converted to a proper validator object. This to me is still a mystery because from what I can tell it appears to be totally random.</p> <p>What happens is when the Page_ClientValidate is kicked off, it tries to invoke each validators validate function but it can't because evaluationfunction == undefined. Instead of using false as the default it assumes true and so no validation actually happens and everything appears valid from the client side. the <strong>if (typeof(val.evaluationfunction) == "function")</strong> is never true so it falls back on the prior assignment of <strong>val.isvalid = true;</strong>.</p> <pre><code>function ValidatorValidate(val, validationGroup, event) { val.isvalid = true; if ((typeof(val.enabled) == "undefined" || val.enabled != false) &amp;&amp; IsValidationGroupMatch(val, validationGroup)) { if (typeof(val.evaluationfunction) == "function") { val.isvalid = val.evaluationfunction(val); if (!val.isvalid &amp;&amp; Page_InvalidControlToBeFocused == null &amp;&amp; typeof(val.focusOnError) == "string" &amp;&amp; val.focusOnError == "t") { ValidatorSetFocus(val, event); } } } ValidatorUpdateDisplay(val); } </code></pre> <p><strong>[How did I fix it?]</strong></p> <p>To fix this I wrote a routine that can be called after the DOM has finished loading. This routine loops all of the validator controls and tries to create the object properties from the raw markup data in the SPAN using JQuery, although you could probably use any other equivalent tool to get the same result. This routine does not fix all of the validator controls, mainly required field validators and regular expression validators. You'll need to change it if your using other validation controls that have additional properties.</p> <pre><code>function fixValidatorProperties() { if (Page_Validators &amp;&amp; Page_Validators[0] &amp;&amp; Page_Validators[0].evaluationfunction == undefined) { var val = null; for (i = 0; i &lt; Page_Validators.length; i++) { val = Page_Validators[i]; if (val.initialvalue == undefined) val.initialvalue = ""; if ($(val).attr("evaluationfunction")) eval("val.evaluationfunction = " + $(val).attr("evaluationfunction") + ";"); if ($(val).attr("controltovalidate")) val.controltovalidate = $(val).attr("controltovalidate"); if ($(val).attr("errormessage")) val.errormessage = $(val).attr("errormessage"); if ($(val).attr("Dynamic")) val.Dynamic = $(val).attr("Dynamic"); if ($(val).attr("initialvalue")) val.initialvalue = $(val).attr("initialvalue"); if ($(val).attr("ValidationExpression")) val.validationexpression = $(val).attr("ValidationExpression"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload