views:

234

answers:

2

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??

A: 

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?

Joel Coehoorn
If so, calling Page.Validate() method before might help
Dan Diplo
i am clicking a "Next" button and going to the next page i am newbie here please help
A: 
  • 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.

Rob Allen
Validation group is correct; Causevalidation is set to true ;control to validate is currect ; Use submit behavior is true now ; but i didnt understand what i have to do in the code ..i am newbie here please elaborate
what you mean by wrap the page ??
@Jaison - Your Page Changing code, not the page itself. So if you have something like `response.redirect(nextPage, false);` you'll want to put that in an `If` statement so it does not fire if `Page.IsValid` returns `False`.
Rob Allen
Validation grooup worked fine .. thanks for the help !!