MaskedEditValidator does not call Clientvalidationfunction

708 Views Asked by At

I want to use my own Function to validate the Value of a textbox. It's because the format is like 'MMM YYYY' (e.g.: Dec 2014).

I am using the AjaxControlToolkit. I saw that the maskededitvalidator provides me with the property ClientValidatonFunction, such as the CustomValidator does.

The problem is that it seems that this function never gets called.

Here my little JavaScript-function:

<script type="text/javascript">
  function MyFunction(sender, args) {
    alert("foo");
  }
</script>

Here my ASP

<asp:textbox id="StartTextBox" cssclass="textbox"
  style="width: 60px;" validationgroup="Dialog"
  causesvalidation="false" runat="server">
</asp:textbox>
<ajaxtoolkit:calendarextender id="StartCalendarExtender"
  targetcontrolid="StartTextBox" format="MMM yyyy"
  OnClientHidden="onCalendarHidden_StartTextBox"
  OnClientShown="onCalendarShown_StartTextBox"
  BehaviorID="calendar_StartTextBox" runat="server">
</ajaxtoolkit:calendarextender>
<ajaxtoolkit:maskededitextender id="StartMaskedEditExtender"
  targetcontrolid="StartTextBox" enabled="false"
  mask="??? 9999" masktype="Date" oninvalidcssclass="textbox_invalid"
  runat="server">
</ajaxtoolkit:maskededitextender>
<ajaxtoolkit:maskededitvalidator id="StartMaskedEditValidator"
  controlextender="StartMaskedEditExtender" display="Dynamic"
  controltovalidate="StartTextBox"
  clientvalidationfunction="MyClientFunction" enableclientscript="true"
  enabled="true" isvalidempty="false" runat="server">
</ajaxtoolkit:maskededitvalidator>

My Alert never apears.

The question is what am I doing not right or what have I to change to make the clientvalidationfunction gets called?

AoE

1

There are 1 best solutions below

1
On

I suspect you might have a javascript error if you switch the debugger on the client side. I also suspect that you are running with the scripts in "release" mode, therefore minified. You might want to check this. To confirm, make the scripts "debug" mode (switch ScriptMode to Debug in your ScriptManager) and hopefully it will work.

This is a known bug since at least 2011, still not fixed in the Ajax Toolkit as of the December 2013 release.

Bug report: http://ajaxcontroltoolkit.codeplex.com/workitem/26740

It is because the debug mode/full/non-minified version says this:

var args = { Value:mask, IsValid:true };
eval(value.ClientValidationFunction + "(value, args);");

But the release mode/minified version says something like this:

var s = { Value:mask, IsValid:true };
eval(n.ClientValidationFunction + "(value, args);");

As you can see, "value" and "args" inside the string inside the eval statement have not been touched, but have been changed to n and s respectively elsewhere (value always seems to be minified to n, however, args seems to be minified to c, e, s and v in the 5 occurrences of this eval in this file).

There are various workarounds, none really great. See the link above, but basically:

  • only use the debug/full/non-minifed version for this extender
  • vitor_canova uses closures (I've not tested this one)
  • i previsouly built my own AjaxControlToolkit with the source and fixed the minified version there, but that method doesn't work anymore with the latest version, so I'm trying something else as we speak...