rschaeferhig
asked on
CustomValidaor and Client-side validation
I have a text box that I need to run a custom validator on to make sure the max length isn't exceeded. The HTML for the TextBox and Validaor are below along with the Javascript validation function. I pretty much copied this out of an example on MSDN. it doesn't work. When I leave the TextBox I get a JS error: Microsoft JScript runtime error: 'Value.length' is null or not an object
Any help is greatly appreciated.
Any help is greatly appreciated.
<asp:TextBox runat="server" ID="emer_phone_quantity" Width="30px" Height="20px" MaxLength="10" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Phone Quantity length must be no greater than 10"
Text="*" ControlToValidate="emer_phone_quantity" ClientValidationFunction="ValidateLength10" />
In the Page Head section:
<script type="text/javascript">
function ValidateLength10(args, event) {
args.IsValid = (args.Value.length <= 10)
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You're painfully right. I'm under a time constraint rewriting an ASP/VBScript app to .Net and I didn't even think about it. I just implemented what was in the original code... Duhh..
function ValidateLength10(oSrc,args
args.IsValid = (args.Value.length <= 10)
}