1

I'm new to using c# in asp.net

I was just wondering what the best methods of validation are for when it comes to checking a textbox that has to be number's (and 1 decimal point) only, I've read about ajax but I understand that this only works if the client supports it, so I'm now looking into new methods.

Also do these validation methods have the ability to prevent a event such as a button press from triggering and causing the web application to break?

9
  • 3
    Always validate data at client side as well as server side (in code behind). Commented May 17, 2013 at 12:15
  • 1
    @Freelancer This is because to give 2 level of security. Client validation is prone to get hacked, server validation saves you to open your database to hackers Commented May 17, 2013 at 12:17
  • 1
    @Freelancer The client side validation is only for the ease of the user, refreshless validation. However, this is not at all secure. Validation should always take place both at the client and server. Commented May 17, 2013 at 12:18
  • 1
    @Freelancer Everything going at server level puts some overhead however this is recommended if you are having confidential data. But playing with confidential data is more important and this overhead can be ignored. It will be a nightmare if your database is exposed to hackers :( Commented May 17, 2013 at 12:22
  • 2
    @NipunAmbastha ohh, thanx , from 2mmorow, 2 level validation. Thanx a lot. Commented May 17, 2013 at 12:24

1 Answer 1

5

Always validate data at client side as well as server side (in code behind). For example you can use the asp.net provided validation control which will provide you with Client side validation, In server side validation (in C#) you can implement your own logic for data validation. For example in your case you can use double.TryParse to see if the string entered in the TextBox is a valid double number.

The reason to have Both types of validation is:

  • Client may have disabled javascript on the browser.
  • Client's browser doesn't support Javascript (see this question)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.