RequiredFieldValidator with ValidationGroup doesn't validate

谁说胖子不能爱 提交于 2019-12-04 11:00:38

You are missing Validation Group on the Validators.

There's no need to specify validation group on the controls(textboxes) instead specify the validation group on the validators and the button on which you want the valid data to be posted!

Try this one:

    Name: 
<asp:TextBox ID="txtNewName" runat="server" />
<asp:RequiredFieldValidator ID="vldtxtNewName" runat="server"
     ControlToValidate="txtNewName" ValidationGroup="NewDepartmentValidationGroup" 
     ErrorMessage="Required Field" /><br />
Description: 
<asp:TextBox ID="txtNewDescription" runat="server" />
<asp:RequiredFieldValidator ID="vldtxtNewDescription" runat="server" 
    ControlToValidate="txtNewDescription" ErrorMessage="Required Field"
    ValidationGroup="NewDepartmentValidationGroup" /><br />
<asp:Button ID="cmdCreate" runat="server" Text="Create"
     ValidationGroup="NewDepartmentValidationGroup" OnClick="cmdCreate_Click" />
Aghilas Yakoub

try with ValidationGroup="NewDepartmentValidationGroup" in the validators not in textbox

<asp:TextBox ID="txtNewName" runat="server"  />
        <asp:RequiredFieldValidator ID="vldtxtNewName" runat="server" ControlToValidate="txtNewName"  ValidationGroup="NewDepartmentValidationGroup"
            ErrorMessage="Required Field" /><br />
Description: 
<asp:TextBox ID="txtNewDescription" runat="server"          
    />

<asp:RequiredFieldValidator ID="vldtxtNewDescription" runat="server" 
    ControlToValidate="txtNewDescription" ErrorMessage="Required Field" ValidationGroup="NewDepartmentValidationGroup"/><br />

<asp:Button ID="cmdCreate" runat="server" Text="Create"
      ValidationGroup="NewDepartmentValidationGroup" OnClick="cmdCreate_Click" causesvalidation="true" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!