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
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:
But the release mode/minified version says something like this:
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: