I’m using some of the typical ASP.NET’s Validation Controls in my website. Now I’m trying to disable the JavaScript in my browser to test my application and of course the Validation Controls no longer works. I think it’s best to try to make them work using one of the suggested solutions down here instead of reinvesting the wheel and build a validation layer for the page or my objects -Am I thinking right?-
What do you think of these options and why:
-
Include in clicked button’s event a code to check if the page is valid and if not explicitly call the
Page.Validate();method -
Check if whether the JavaScript is enabled and if not I should call
Page.Validate();
If you there’s a better way to do it please let me know.
The validation controls are designed to validate primarily on the server side. The client-side validation is optional (see the
EnableClientScriptproperty). So if they aren’t working with Javascript disabled, then you’re probably missing a little boilerplate code in your page, such as this snippet from the MSDN documentation on Page.IsValid:You can also call
Page.Validateand checkPage.IsValidin your Page’sOnLoadevent, so that you can prevent a postback from proceeding to the next step when the form needs to be re-submitted. You probably don’t even need to callValidate()explicitly —Button.CausesValidationis true by default.