如何让requiredfieldvalidator点击提交按钮后显示错误消息
现在,如果我移出当前文本框,则会显示错误消息。在单击提交按钮之前我不想显示它。
now, the error message will display if I move out of current textbox. I don't want to display it until I click submit button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
当为验证器启用 ClientScript 时,这是不可能的。默认情况下,您的验证器会启用 ClientScript。您需要通过在源中将 EnableClientScript 设置为 False 来禁用此功能。
现在,在提交按钮的事件处理程序中调用 Page.Validate() 和 Page.IsValid 来查看每个验证器是否都通过了测试。
例子:
This isn't possible when ClientScript is enabled for your validators. And the ClientScript is by default enabled for your validators. You need to disable this by settings EnableClientScript to False in your source.
Now in the event handler of your submit button call Page.Validate() and Page.IsValid to see if every validators did pass the test.
Example:
在页面上的某处使用验证摘要控件...
然后进行验证:
如果您不需要立即反馈,请删除“*”...错误消息显示在
中> 控制提交表单的时间。Use a validation summary control somewhere on your page...
Then to validate:
Remove the "*" if you don't want immediate feedback... the errormessage is displayed in the
<asp:validationsummary>
control when you submit the form.通常它仅在您输入文本、再次删除然后移出文本框时出现。我认为这是设计使然。尝试更改 EnableClientScript 属性。
Normally it appears only when you enter text, delete it again and then move out of the textbox. I think this is by design. Try to change EnableClientScript property.
将验证器的
forecolor
属性设置为页面的背景颜色。然后在提交按钮的onclientclick
中,将 csscolor
属性更改为所需的颜色:Set the
forecolor
property of the validator to the background color of your page. Then in theonclientclick
of the submit button, change the csscolor
property to the desired color:您可以为不希望进行验证的按钮设置
CausesValidation="False"
。You could set
CausesValidation="False"
for the button for which you don't want validation to happen.尝试这个来创建动态单选按钮以及所需的字段验证器......
Try this one for creating dynamic radio buttons along with required field validators...