ASP.net range validator moving to next page
-
05-07-2019 - |
Question
I have put a range validator in a asp.net text box control in my webpage; whenever the range is not meeting ; it will dispay the error message,
But it is moving to the next page. how i can prevent it from moving to the next page after the click of submit button while the range not met??
Solution
Make sure your submit button is in the same
ValidationGroup
as your range validator. This is particularly true if you have more than oneValidationGroup
defined.Make sure the property
CausesValidation
is not set to false on the button. The default value isTrue
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 toFalse
, or in some cases, when using asych AJAX callbacks) then you will want to wrap your page changing code in anIf
block which checks forPage.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.
OTHER TIPS
Code?
Are you submitting directly to the next page rather than posting back to the same page and redirecting?
Are you redirecting in Page_Load, which occurs before validation?