Link to home
Start Free TrialLog in
Avatar of rschaeferhig
rschaeferhigFlag for United States of America

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.
<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>

Open in new window

Avatar of HarryNS
HarryNS

Change you javascript function to this,

function ValidateLength10(oSrc,args) {
     
                  args.IsValid = (args.Value.length <= 10)
 
            }
ASKER CERTIFIED SOLUTION
Avatar of HarryNS
HarryNS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rschaeferhig

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..