Csharp control validating

In this particular example the solution is obvious – return boolean value instead of throwing exceptions – but let’s dive deeper and look at more complex use cases.Perhaps, the most common practice for exceptions is to use them to state that input validation is failed. Yep, both of them allows you to easily break through the code to the point where you need to appear leaving irrelevant code paths behind.The Required Field Validator is actually very simple, and yet very useful.You can use it to make sure that the user has entered something in a Text Box control.

Moreover, it violates the principle of least astonishment by throwing an exception even in case of success.

Now you will see the browser posting back to the server, but the result will be the same - the validator still works!

Right now, the button does nothing, besides posting back if the page is valid.

The client side validation is accomplished through the Client Validation Function property.

The client side validation routine should be written in a scripting language, such as Java Script or VBScript, which the browser can understand.

Leave a Reply