For instance, it would be possible to enter nothing, or enter a piece of text instead of a number.You should always consider this when using the Compare Validator.The Compare Validator might not be the most commonly used validator of the bunch, but it's still useful in some cases.It can compare two values, for instance the values of two controls.Whenever a web form is submitted, you should check to make sure that all fields contain valid data to help prevent your web site from being hacked.In this case we need to check to see if the user has entered a number into a text box called TXT_Number after clicking a button named Button1.This article will explain how to make sure that the user only submits a number to your .
Now, try running the website, and test the two new fields.In this case, we use the Less Than operator, because we wish for the first control to have the smallest value.We set the type to integer, because we want to compare integers.If an exception is thrown then you know that the user did not enter an Integer number (or the number is too large or too small to fit into an Integer). (Java Script) I bet you're wondering how to use this code in your . Or you could register the script using Client Script.Example: (VB) To reiterate:in the above code, if the text value in the TXT_Number text box was not a number then Integer. The exception is then caught and an error message is displayed in the label LBL_Number Error. This method also tries to convert string into a number. Register Startup Script: (VB) It is advisable to use this second method if you are including the script into a web user control to ensure that the script is only written to the browser once since it's possible to have multiple instances of this control on the web site.