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

Want to only validate on submit

2 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 22 Oct 2008, 04:31 PM
I have a radgrid, and 3 of my fields have validators on them. The login_name, password and email have requiredfieldvalidator and the email also has a regularexpression validator. I do not want the fields to be validated while entering data, only when the user clicks the update or insert button. This is becasue I also have a dropdown combo box in the form and when this dropdown combo changes, I have 2 embedded grids that change based on the choice in the combo box. But if one of the 3 fields fails validation, and the user changes the combobox, the 2 embedded grids do not reload. My fix to this would be the validation not occur until update or insert is clicked, but I cant get this work work.

Here are the 3 columns with the validation and then the combobox and one of the embedded grids:



<Columns>
        <telerik:GridEditCommandColumn ButtonType="ImageButton"  UniqueName="EditCommandColumn1">
                    <HeaderStyle Width="20px" />
        </telerik:GridEditCommandColumn>
        <telerik:GridBoundColumn DataField="user_id" UniqueName="user_id" Visible="false" ReadOnly="true" ></telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="package_cd" UniqueName="package_cd" Visible="false" ReadOnly="true" ></telerik:GridBoundColumn>

        <telerik:GridTemplateColumn HeaderText="Seat(User)" SortExpression="login_name" UniqueName="login_name" >
          <ItemTemplate>
             <asp:Label ID="login_name"   runat="server"  Text='<%#Eval("login_name") %>'></asp:Label>
          </ItemTemplate>
          <EditItemTemplate>
             <asp:TextBox ID="loginname" Text='<%#Eval("login_name") %>'  runat="server"  OnTextChanged="change_loginName"></asp:TextBox>
             <asp:RequiredFieldValidator id="loginnameRequiredFieldValidator" runat="server" ErrorMessage="* User name required" Display="Dynamic"
        ControlToValidate= "loginname"></asp:RequiredFieldValidator>
          </EditItemTemplate>
        </telerik:GridTemplateColumn>
        
        <telerik:GridTemplateColumn HeaderText="Password" SortExpression="password" UniqueName="password"  EditFormColumnIndex="1" AllowFiltering="false">
          <ItemTemplate>
             <asp:Label ID="password"   runat="server"  Text='<%#Eval("password") %>'></asp:Label>
          </ItemTemplate>
          <EditItemTemplate>
             <asp:TextBox ID="editPassword" Text='<%#Eval("password") %>'  runat="server"  OnTextChanged="change_Password" ></asp:TextBox>
             <asp:RequiredFieldValidator id="passwordRequiredFieldValidator" runat="server" ErrorMessage="* Password required" Display="Dynamic"
        ControlToValidate= "editPassword"></asp:RequiredFieldValidator>
          </EditItemTemplate>
        </telerik:GridTemplateColumn>
        
        <telerik:GridTemplateColumn HeaderText="Email" SortExpression="email" UniqueName="email" >
          <ItemTemplate>
             <asp:Label ID="email"   runat="server"  Text='<%#Eval("email") %>'></asp:Label>
          </ItemTemplate>
          <EditItemTemplate>
             <asp:TextBox ID="editEmail" Text='<%#Eval("email") %>'  runat="server"  OnTextChanged="change_email"></asp:TextBox>
             <asp:RequiredFieldValidator id="emailValidator1" runat="server" ErrorMessage="* Email required"    Display="Dynamic"
                 ControlToValidate= "editEmail"></asp:RequiredFieldValidator>        
             <asp:RegularExpressionValidator Runat="server" ErrorMessage="* Invalid E-mail Address" ID="emailValidator2"  Display="Dynamic"
                 ControlToValidate="editEmail" ValidationExpression=".+@.+\.[a-z]+"></asp:RegularExpressionValidator>
          </EditItemTemplate>
          
        </telerik:GridTemplateColumn>

<telerik:GridTemplateColumn HeaderText="Package"  UniqueName="DefaultPackage" EditFormColumnIndex="1" >
                       <HeaderStyle Width="100%" />
                        <ItemTemplate>
                            <asp:Label runat="server" ID="Label1" Text='<%#Eval("package_name") %>'></asp:Label>
                            <telerik:RadToolTip runat="server" ID="RadToolTip1" TargetControlID="Label1"
                                Skin="Web20" ShowDelay="1000" AutoCloseDelay="200000" Font-Names="arial"
                                Font-Size="XX-Large" BorderStyle="Inset" HideDelay="100000" ManualClose="False"
                                Position="BottomRight" Sticky="True" Width="300">   
                                    <asp:Label runat="server" ID="Label3" Text='<%#Eval("descriptions") %>'></asp:Label><br/>                                                  
                             </telerik:RadToolTip>
                        </ItemTemplate>
                        <EditItemTemplate>
                        <telerik:RadComboBox  ID="package"  Width="220px"  runat="server"  OnSelectedIndexChanged="RadComboBoxSelectedIndexChanged"
                                MarkFirstMatch="True"  AllowCustomText="True" DataSourceID="ContentCentralPackages"   EmptyMessage="Select a package"
                              ExpandAnimation-Type="None"  CollapseAnimation-Type="None" AutoPostBack="true" AppendDataBoundItems="false"  OnClientSelectedIndexChanging="setnewprice"
                                DataTextField="package_name" DataValueField="package_cd" DropDownWidth="650px"  OnClientKeyPressing="setnewprice"
                               Skin="WebBlue"  SelectedValue='<%# Bind("package_cd") %>'
                                EnableVirtualScrolling="True" HighlightTemplatedItems="True">
                             <ExpandAnimation Type="None" />
                             <CollapseAnimation Duration="200" Type="None" />
                             
                             
                          <HeaderTemplate>
                           <table style="width: 620px; text-align: left">
                            <tr>
                                <td style="width: 170px;">
                                    Package Name
                                </td>
                                <td style="width: 450px;" >
                                    Description
                                </td>
                                <td style="width: 0px;" >
                                    
                                </td>
                               
                            </tr>
                          </table>
                        </HeaderTemplate>
                    <ItemTemplate>
                        <table style="width: 620px; text-align: left">
                            <tr>
                                <td style="width: 170px;" valign="top">
                                    <%# DataBinder.Eval(Container.DataItem, "package_name") %>
                                </td>
                                <td style="width: 450px;">
                                    <%# DataBinder.Eval(Container.DataItem, "descriptions") %>
                                </td>
                               
                                
                            </tr>
                        </table>
                    </ItemTemplate>
            
                          </telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                   <telerik:GridTemplateColumn HeaderText="Package Price" UniqueName="NumericPrice" AllowFiltering="false" >
                      <ItemTemplate>
                        <telerik:RadNumericTextBox ID="inGridPkgPrice" runat="server"  Price='<%# Eval("packageprice") %>'  
                                    Culture="English (United States)" Type="Currency"   DbValue='<%# DataBinder.Eval(Container.DataItem, "packageprice") %>'  
                                      Width="125px"  OnTextChanged="RadNumericInlineGridTextChanged" AutoPostBack= "true">  
                                     
                         </telerik:RadNumericTextBox>
                      </ItemTemplate>
                      <EditItemTemplate>
                        <telerik:RadNumericTextBox ID="inFormPkgPrice" runat="server"  Price='<%# Eval("packageprice") %>'  
                                    Culture="English (United States)" Type="Currency"   DbValue='<%# DataBinder.Eval(Container.DataItem, "packageprice") %>'  
                                      Width="125px"   OnTextChanged="RadNumericDefaultPackageTextChanged">  
                                      <ClientEvents OnLoad="PriceBoxLoad"  />
                                  </telerik:RadNumericTextBox>
                      </EditItemTemplate>
                    
                    </telerik:GridTemplateColumn>
                      <telerik:GridMaskedColumn  DataField="packageprice"  Mask="$ #####.##" DataFormatString="{0:C2}" HeaderText="Package Price" Display="true" UniqueName="readonlyPackagePrice"
                                  readonly="true"  AllowFiltering="false">
                         <ItemStyle HorizontalAlign="Right" />
                      </telerik:GridMaskedColumn>
                   
                        <telerik:GridMaskedColumn  DataField="packagealaprice"  Mask="$ #####.##" DataFormatString="{0:C2}" HeaderText="Ala Carte Price" Display="true" UniqueName="packagepriceala"
                                  readonly="true"  AllowFiltering="false">
                         <ItemStyle HorizontalAlign="Right" />
                      </telerik:GridMaskedColumn>
       
            <telerik:GridTemplateColumn EditFormHeaderTextFormat=""  HeaderStyle-VerticalAlign="Top" Visible="false" UniqueName="PackagePriceGrid">
             <EditItemTemplate>
               <telerik:RadGrid ID="PackagePriceGrid" runat="server" AutoGenerateColumns="False" DataSourceID="spAddNewsTradeProduct"  
                                GridLines="None" Skin="Office2007" onitemdatabound="PackagePriceGrid_ItemDataBound" OnItemCommand="PackageGrid_ItemCommand"
                              ShowStatusBar="True" OnPreRender="PackagePriceGrid_PreRender" >
                  <MasterTableView CommandItemDisplay="None" EditMode="InPlace" DataKeyNames="service_id,Checked" >   
                    <Columns>
                       <telerik:GridBoundColumn  UniqueName="service_id" DataField="service_id" Visible="false" Display="false">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="service_name" HeaderText="Default Package"  Display="true" UniqueName="service_name" >
                       </telerik:GridBoundColumn>
                       <telerik:GridTemplateColumn HeaderText="Purchased" UniqueName="CHECKED">
                        <ItemTemplate>
                          <asp:CheckBox ID="Entitled"  Checked='<%# Eval("Checked") %>' runat="server" />
                                 </ItemTemplate>
                          </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn  UniqueName="PKGPRICE" HeaderText=""  Display="false" >
                        <ItemTemplate>
                                  
                                  <telerik:RadNumericTextBox ID="PKGPRICE" runat="server"  Price='<%# Eval("Price") %>'
                                    Culture="English (United States)" Type="Currency"   DbValue='<%# DataBinder.Eval(Container.DataItem, "Price") %>'  
                                      Width="125px" >  
                                      <ClientEvents    OnLoad="priceLoaded"  OnValueChanged="priceLoaded" />
                                  </telerik:RadNumericTextBox>
                               </ItemTemplate>
                           <EditItemTemplate>
                                  
                                  <telerik:RadNumericTextBox ID="PKGPRICE" runat="server"  Price='<%# Eval("Price") %>'
                                    Culture="English (United States)" Type="Currency"   DbValue='<%# DataBinder.Eval(Container.DataItem, "Price") %>'  
                                      Width="125px" >  
                                      <ClientEvents    OnLoad="priceLoaded"  OnValueChanged="priceLoaded" />
                                  </telerik:RadNumericTextBox>
                               </EditItemTemplate>
                         </telerik:GridTemplateColumn>
                     </Columns>
                    
                  </MasterTableView>
                </telerik:RadGrid>                    
              </EditItemTemplate>
             <HeaderStyle VerticalAlign="Top"></HeaderStyle>
          </telerik:GridTemplateColumn>   
         

2 Answers, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 24 Oct 2008, 02:46 PM
Hello Laura,

Try setting the CauseValidation property of the combobox to false and check if it makes any difference. Another option is to use ValidationGroup - assign same ValidationGroup to the validators and the Update/Insert button.

Give it a try and let me if this helps.

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Laura
Top achievements
Rank 1
answered on 24 Oct 2008, 03:08 PM
Thanks! Just what I was looking for. This worked.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Laura
Top achievements
Rank 1
Share this question
or