I am using ASP.NET 4.
I would like check the length for a string inserted in a TextBox. Ex: Input Name no more than 255 characters.
My questions:
- Which Web Controls for Validation I can use in ASP.NET?
- Web Controls for Validation validate both Client side and server side? I mean without Java script enabled the Control is able to validate (on server side)?
Thanks for your time
You can combine the
MaxLengthproperty of the text box for user convenience, and theRegularExpressionValidatorfor client and server-side validation.If client-side validation fails, a postback is prevented. If javascript is disabled, or your client is an attacker, validation still occurs on the server side.
To query the page on the server-side to see if validation succeeded, check the
IsValidproperty on the page, and take action accordingly.You can check out this resource for an example of
IsValidusage.http://msdn.microsoft.com/en-us/library/system.web.ui.page.isvalid.aspx