且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使的RequiredFieldValidator错误消息显示后,点击提交按钮

更新时间:2022-12-07 09:09:17

当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
}