简体   繁体   中英

problem with asp.net validationcontrol

I have a textbox and I have set required validationcontrol on it on click of a button.

<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
   <asp:RequiredFieldValidator ID="rfvname" runat="server" ControlToValidate="name" ErrorMessage="Name is required" Display="Dynamic" />
   </td>

but the problem is when I am clicking on modify shared webpart and when I click on APPLY or OK button it is not saving as my form is empty . and I can't put CausesValidation="false" on that button as this button is by default in sharepoint.

Any idea how to resolve this...?

您可以使用ValidationGroup属性将所有Validator和Validation字段分组在一起。

Yes using the ValidationGroup tag will help to relate the controls in a single form and will tell the submit button which fields are associated. Also make sure you have a ValidationSummary control on the page with the same ValidationGroup value. Also consider adding an InitialValue="" onto the TextBox control.

<asp:ValidationSummary ID="vs1" ShowMessageBox="true" ShowSummary="false" DisplayMode="List" runat="server" ValidationGroup="Form" HeaderText="There were problems with your submission:" />
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" ValidationGroup="Form" runat="server" ControlToValidate="name" InitialValue="" ErrorMessage="Name is required" Display="Dynamic" />
<asp:LinkButton ID="lnkSubmit" Text="Submit" OnClick="lnkSubmit_Click" ValidationGroup="Form" runat="server"></asp:LinkButton>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM