Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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

Posted
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?

Posted
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!

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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:)

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

Posted (edited)

I just figured it out.

 

Seems to be ok. Entry must be from 10 to 40 characters.

 

\w{10,40}

 

Thanks all!!

Edited by Muhad

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...