This is a migrated thread and some comments may be shown as answers.

validate checkboxed checked in InsertFormtemplate

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 08 Jun 2012, 07:34 PM
I have validated all my controls but one and it is a checkbox on the form that needs to be validated that its checekd before submittal.  How can I achieve this on a radgrid insert, I could do server side but looking for a client side solution.

<FormTemplate>
                                   <table width="100%">
                                       <tr
                                           <td style="width:50%" align="right">Enter Last Name First Name of User </td>
                                           <td style="width:50%" align="left">
                                               <asp:TextBox ID="txtUser" runat="server" Width="260px"></asp:TextBox>
                                               <asp:AutoCompleteExtender ID="txtUser_ACE" runat="server" DelimiterCharacters="" Enabled="True" ServiceMethod="Findname" ServicePath="~/iMACService.asmx" TargetControlID="txtUser"
                                                UseContextkey="true" MinimumPrefixLength="2" OnClientItemSelected="SelectedName" EnableCaching="true" CompletionInterval="1" />
                                                <asp:TextBoxWatermarkExtender ID="txtName_WME" runat="server" TargetControlID="txtUser" WatermarkText="Enter Last Name First Name" WatermarkCssClass="WaterMark" />
                                                <asp:FilteredTextBoxExtender ID="txtUser_FTE" runat="server" TargetControlID="txtuser" FilterType="Custom, LowerCaseLetters, UpperCaseLetters"></asp:FilteredTextBoxExtender>
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Enter EDIPI </td>
                                           <td style="width:50%" align="left">
                                               <asp:TextBox ID="txtEDIPI" runat="server" Width="160px" MaxLength="10"></asp:TextBox>
                                               <asp:RequiredFieldValidator ID="valEDIPI" runat="server" ForeColor="Red" ControlToValidate="txtEDIPI" Display="Dynamic" SetFocusOnError="true" ErrorMessage="* Enter EDIPI" />
                                               <asp:FilteredTextBoxExtender ID="txtEDIPI_FTE" runat="server" TargetControlID="txtEDIPI" FilterType="Numbers"></asp:FilteredTextBoxExtender>
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Pick Type of Investigation </td>
                                           <td style="width:50%" align="left">
                                               <asp:DropDownList ID="ddlInvestigation" runat="server" Width="165px"></asp:DropDownList>
                                               <asp:RequiredFieldValidator ID="valInvest" runat="server" ForeColor="Red" ControlToValidate="ddlInvestigation" Display="Dynamic" SetFocusOnError="true" ErrorMessage="* Enter Investigation Type" InitialValue="0" />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Pick Date of Investigation </td>
                                           <td style="width:50%" align="left">
                                               <asp:textbox ID="txtDtInvest" runat="server" Width="160px" style="cursor:pointer"></asp:textbox>
                                               <asp:CalendarExtender ID="calExt" runat="server" TargetControlID="txtDtInvest" PopupPosition="BottomRight"></asp:CalendarExtender>
                                               <asp:RequiredFieldValidator ID="valdtInvest" runat="server" ForeColor="Red" ControlToValidate="txtDtInvest" Display="Dynamic" SetFocusOnError="true" ErrorMessage="* Enter Investigation Date" />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Pick Clearance </td>
                                           <td style="width:50%" align="left">
                                               <asp:DropDownList ID="ddlClearance" runat="server" Width="165px"></asp:DropDownList>
                                               <asp:RequiredFieldValidator ID="valClear" runat="server" ForeColor="Red" ControlToValidate="ddlClearance" Display="Dynamic" SetFocusOnError="true" ErrorMessage="* Enter Clearance Level" InitialValue="0" />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Pick IT Level </td>
                                           <td style="width:50%" align="left">
                                               <asp:DropDownList ID="ddlITLevel" runat="server" Width="165px"></asp:DropDownList>
                                               <asp:RequiredFieldValidator ID="valItlevel" runat="server" ForeColor="Red" ControlToValidate="ddlITLevel" Display="Dynamic" SetFocusOnError="true" ErrorMessage="* Enter IT Level" InitialValue="0" />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Check Approval </td>
                                           <td style="width:50%" align="left">
                                               <asp:CheckBox ID="cbApproval" runat="server" Text="I have done a background investigation of the above individual and approve." />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Check DisApprove </td>
                                           <td style="width:50%" align="left">
                                               <asp:CheckBox ID="cbDisApprove" runat="server" Text="I have done a background investigation of the above individual and Disapprove." />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr
                                           <td style="width:50%" align="right">Uploaded 2875 </td>
                                           <td style="width:50%" align="left">
                                               <asp:CheckBox ID="cbUpload" runat="server" Text="I have upload the original 2875 to FileNet Location." />
                                           </td>
                                       </tr>
                                       <tr>
                                           <td style="height:5px"></td>
                                       </tr>
                                       <tr>
                                           <td style="width:50%" align="right"></td>
                                           <td style="width:50%" align="left">
                                               <asp:LinkButton ID="lnkSubmit" runat="server" text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Approve", "Update") %>' 
                                               CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'></asp:LinkButton>
                                                     
                                               <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                           </td>
                                       </tr>
                                   </table>
                               </FormTemplate>

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Jun 2012, 04:59 PM
Hello,

Please check below code snippet.
function myfunction(chk, rfv) {
              var ochk = document.getElementById(chk);
              var orfv = document.getElementById(rfv);
              if (ochk.checked) {
                  ValidatorEnable(orfv, false);
                  return true;
              }
              else {
                  ValidatorEnable(orfv, true);
                  return false;
              }
          }
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
                   if(e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                GridEditFormItem item = e.Item as GridEditFormItem;
                LinkButton lnkSubmit = item.FindControl("lnkSubmit") as LinkButton;
                CheckBox mychk = item.FindControl("mychk") as CheckBox;
                RequiredFieldValidator RequiredFieldValidator1 = item.FindControl("RequiredFieldValidator1") as RequiredFieldValidator;
                lnkSubmit.Attributes.Add("onclick", "return myfunction('" + mychk.ClientID + "','" + RequiredFieldValidator1.ClientID + "');");
            }
 
}
<EditFormSettings EditFormType="Template">
                   <FormTemplate>
                       <asp:CheckBox ID="mychk" runat="server" />
                       <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="dummytext"
                           ErrorMessage="please check checkbox" Display="Dynamic" Enabled="false"></asp:RequiredFieldValidator>
                       <asp:TextBox ID="dummytext" runat="server" Style="display: none;"></asp:TextBox>
                       <br />
                       <asp:LinkButton ID="lnkSubmit" runat="server" Text="mycommand" CommandName="Update"></asp:LinkButton>
                       <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="false" CommandName="Cancel"
                           Text="Cancel"></asp:LinkButton>
                   </FormTemplate>
               </EditFormSettings>


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or