Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is Custom validation firing?

Status
Not open for further replies.

stephenk1973

Technical User
Jun 11, 2003
246
GB
I have tried to create my first custom validation on a text box using funciton on the net. The text box is to be passed to a stored procedure.

Validation always returns false, i'm not sure if the funciton is being called at all. Validation occurs when you press 'enter', and it always seem to pass the variable to the procedure regradless.

Any other validation ( required, range etc) all work fine, where am i going astray or is there a good 101 on custom validation.

Thanks

Stephen


Function IsValidField(ByVal stext)
{
var ValidChars = "0123456789, ";
var IsGood=true;
var Char;

alert(document.Form1.textbox1.Value);

for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsGood = false;
}
}
return IsGood;

}


<asp:TextBox ID="TextBox1"
runat="server">
</asp:TextBox>
<asp:CustomValidator
ID="CustomValidator1"
runat="server"
ControlToValidate="TextBox1"
ErrorMessage="CustomValidator"
ClientValidationFunction="IsValidField">*
</asp:CustomValidator>
 
Have you tried debugging the project and stepping through the code? That will tell you if it has been called...

Also, a quick tets would be to put an "alert" box in your function.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I am not quite sure.

- The IsValidField get an argument but i don't see where you assign it.
- I think that the javascript funtion (client side) for validation purpose must be like: function a_name(sender, e) { ... }.

There is an alternative way. Why do you want to do the validatin on the client side? (speed?)

- Double click on the CustomValidator and see the events that it can handle.
- USe of regEx ?
 
noticed a couple of things:

this:
Function IsValidField(ByVal stext)

should be:
function IsValidField(sender,args)


1. ByVal is NOT a javascript function
2. CustomValidator functions will take 2 parameters (in ASP.NET 1.1 atleast)...



Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top