Muhad Posted December 13, 2003 Posted December 13, 2003 I am suffering from Validatoritis. This is a really bad brain disease. lolol I have a CustomValidator on my Web form and the ControlToValidate is chosen and the ClientValidationFunction is coded. But this code is not being executed. I do use the If Page.IsValid statement on the Web page too. Any ideas would be appreciated. Quote
Moderators Robby Posted December 13, 2003 Moderators Posted December 13, 2003 Is the ClientValidationFunction on the clent side or server? Quote Visit...Bassic Software
Muhad Posted December 13, 2003 Author Posted December 13, 2003 Is the ClientValidationFunction on the clent side or server? On the Client side; it's in the web page code. Quote
Moderators Robby Posted December 13, 2003 Moderators Posted December 13, 2003 Can you post the relevant code Quote Visit...Bassic Software
Muhad Posted December 13, 2003 Author Posted December 13, 2003 Can you post the relevant code Sure! In web page - Private Sub ValLengthSubject(ByVal source, ByVal arguments) If (Len(arguments.Text) < 10 Or Len(arguments.Text) > 40) Then arguments.IsValid = False setFocus(arguments.ClientID) Else arguments.IsValid = True setFocus(arguments.ClientID) End If End Sub Private Sub linkbtnThreadPost_Click(blah blah) ' a button If Page.IsValid Then do some code ... else don't do some code ... end if End Sub Quote
Administrators PlausiblyDamp Posted December 13, 2003 Administrators Posted December 13, 2003 That looks like server side ASP.Net code inside a script block. The ClientValidationFunction needs to be written in a client side scripting language like JavaScript or VB Script. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Muhad Posted December 13, 2003 Author Posted December 13, 2003 That looks like server side ASP.Net code inside a script block. The ClientValidationFunction needs to be written in a client side scripting language like JavaScript or VB Script. Hummm! Should I put this code into a .vbs file? Quote
Administrators PlausiblyDamp Posted December 13, 2003 Administrators Posted December 13, 2003 How is the script block those functions in declared? (could you post the bit here?) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Muhad Posted December 13, 2003 Author Posted December 13, 2003 How is the script block those functions in declared? (could you post the <script> </script> bit here?) I don't have any <script></script> code! Quote
Administrators PlausiblyDamp Posted December 13, 2003 Administrators Posted December 13, 2003 So those functions are in the code behind page then? If so they will only execute server side (after the postback has occured). Client side validation needs to be in a script language supported by the browser - javascript being the most widely supported. Unfortunately I don't have IIS installed on this PC so I can't test out a working example at the moment. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
FancyKetsup Posted December 14, 2003 Posted December 14, 2003 Be sure to set the OnServerValidate="myFunction" in the validator. If your just checking for length in a text box the RegularExpressionValidator would prob be best to use, it will generate the client side javascript to validate it for you if the browser supports it (the beauty of .Net). But webforms will always validate on the server-side also. Its just nice to catch a trip to the server if the users browser supports client-side validation and like i said asp.net will write the client side script for you if you use one of the packaged validators... if you must use the custom validator then you will need to write your client-side javascript function yourself and point the ClientValidationFunction property to this function. Hope this helps:) Quote
Muhad Posted December 14, 2003 Author Posted December 14, 2003 Be sure to set the OnServerValidate="myFunction" in the validator. If your just checking for length in a text box the RegularExpressionValidator would prob be best to use, it will generate the client side javascript to validate it for you if the browser supports it (the beauty of .Net). But webforms will always validate on the server-side also. Its just nice to catch a trip to the server if the users browser supports client-side validation and like i said asp.net will write the client side script for you if you use one of the packaged validators... if you must use the custom validator then you will need to write your client-side javascript function yourself and point the ClientValidationFunction property to this function.Hope this helps:) I had checked out the RegularExpressionValidator but I couldn't come up with an expression to test the length of a text box. Do you have any ideas how to make a lenght expression? Thanks. I can see I still have a lot to learn. Quote
Muhad Posted December 14, 2003 Author Posted December 14, 2003 (edited) I just figured it out. Seems to be ok. Entry must be from 10 to 40 characters. \w{10,40} Thanks all!! Edited December 14, 2003 by Muhad Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.