ASP.net 范围验证器移至下一页
我在网页的 asp.net 文本框控件中放置了一个范围验证器; 每当范围不满足时; 它会显示错误消息,
但它正在移动到下一页。 如何防止在未满足范围的情况下单击提交按钮后移动到下一页?
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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您的提交按钮与范围验证器位于同一
ValidationGroup
中。 如果您定义了多个ValidationGroup
,则尤其如此。确保按钮上的属性
CausesValidation
未设置为 false。 默认值为True
,因此如果该属性未在 ASPX 或代码隐藏中声明,按钮应触发验证序列。如果您没有使用正常的页面流程(即您的按钮的属性
UseSubmitBehvior
设置为False
,或者在某些情况下,当使用异步 AJAX 回调时)那么您需要将页面更改代码包装在If
块中,该块在触发之前检查Page.IsValid
。仔细检查
ControlToValidate
是否设置为正确的控件,并且它没有通过验证的默认值。仔细检查
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.代码?
您是否直接提交到下一页,而不是回发到同一页面并重定向?
您是否在 Page_Load 中进行重定向,在验证之前发生 /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?