I have put a range validator in a asp.net text box control in my webpage; whenever the range is not meeting; it will display the error message,
But it is moving to the next page. How can I prevent it from moving to the next page after the click of submit button while the range not met??
Make sure your submit button is in the same ValidationGroup
as your range validator. This is particularly true if you have more than one ValidationGroup
defined.
Make sure the property CausesValidation
is not set to false on the button. The default value is True
so if the property is not declared in your ASPX or code behind, the button should fire your validation sequence.
If you are not using the normal page flow, (i.e. your button has the property UseSubmitBehvior
set to False
, or in some cases, when using asych AJAX callbacks) then you will want to wrap your page changing code in an If
block which checks for Page.IsValid
before firing.
Double check that the ControlToValidate
is set to the correct control and that it does not have a default value which passes the validation.