开发者

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 .开发者_Python百科 and I can't put CausesValidation="false" on that button as this button is by default in sharepoint.

Any idea how to resolve this...?


You can use the ValidationGroup property to group all the Validators and validation fields together.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜