views:

35

answers:

2

Hi,

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...?

A: 

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

Paulo Santos
A: 

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