如何使的RequiredFieldValidator错误消息显示后,点击提交按钮 [英] how to make requiredfieldvalidator error message display after click submit button

查看:429
本文介绍了如何使的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.

推荐答案

当ClientScript为你的校验器启用这是不可能的。而ClientScript是为你的校验默认启用。您需要通过设置EnableClientScript在源禁用此为假。

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.

现在在事件处理程序的提交按钮调用Page.Validate()和Page.IsValid,看看每一个验证没有通过测试。

Now in the event handler of your submit button call Page.Validate() and Page.IsValid to see if every validators did pass the test.

例如:

<asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ControlToValidate="txtFirstName" EnableClientScript="false" Display="Dynamic" SetFocusOnError="true" />

Page.Validate();
if (!Page.IsValid)
{
     //show a message or throw an exception
}

这篇关于如何使的RequiredFieldValidator错误消息显示后,点击提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆