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

EditedItem.FindControl not finding control when clientevent present

2 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 12 Nov 2008, 08:47 PM
I have a complex radgrid and everything was working. All I want to do is add an event when the user clicks save in my edit or insert form to validate the input data on the client side and popup a radalert if there is anything wrong with the data. After introducing this to my grid:

<ClientSettings>
             <ClientEvents OnCommand="commandClicked" />
        </ClientSettings>

...
 function commandClicked(sender, eventArgs) {
        var command = eventArgs.get_commandName();
        var arg = eventArgs.get_commandArgument();
        var x = 1;
   }

then the codebehind does not work the same way it did before. I have 2 template columns which are actually grids, and in my server side code I have   updateCommand   code to go through those grids and save the data from the grids to a temporary table. The findcontrol does not find the grids i(they are null) n the templates after I add the client event handler. I does find it in my insert code, but not in my update code. I will first put just the function that is trying to find the control and then the whole code will follow.

protected void usersGrid_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        string tableName = temptablename.Text;
        string packagecd = package_cd.Text;
        //  int sbOrderDetailID = Convert.ToInt32(Session["sbOrderDetailID"]);
        int sbOrderDetailID = Convert.ToInt32(TextBoxOrderDetailID.Text);
        int nUserID = Convert.ToInt32(TextBoxUserID.Text);
        string sLoginName = TextBoxLoginName.Text;
        string sPassword = TextBoxPassword.Text;
        string sEmail = TextBoxEmail.Text;
        string sActive = TextBoxActive.Text;
        // string sPrice = Session["price"].ToString();
        double dblPrice = Convert.ToDouble(RadNumericTextBoxPrice.Value);

        GridEditableItem editedItem = e.Item as GridEditableItem;
        //      UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

        RadGrid PackageGrid = (editedItem.FindControl("PackagePriceGrid") as RadGrid);
        RadGrid alaGrid = (editedItem.FindControl("AlaCartePriceGrid") as RadGrid);

        foreach (GridDataItem item in PackageGrid.Items)
        {
            System.Web.UI.WebControls.CheckBox chkbx = (System.Web.UI.WebControls.CheckBox)item["CHECKED"].FindControl("Entitled");

            int service_id = Convert.ToInt32(PackageGrid.MasterTableView.DataKeyValues[item.ItemIndex]["service_id"]);
            Boolean oldIchecked = Convert.ToBoolean(PackageGrid.MasterTableView.DataKeyValues[item.ItemIndex]["Checked"]);

            Boolean entitled = chkbx.Checked;
            if (oldIchecked != entitled)
                Insert_update_checkbox(temptablename.Text, package_cd.Text, service_id, 0, entitled);

            item.Edit = false;
        }
        PackageGrid.Rebind();

        foreach (GridDataItem item in alaGrid.Items)
        {
            System.Web.UI.WebControls.CheckBox chkbxEntitled = (System.Web.UI.WebControls.CheckBox)item["CHECKED"].FindControl("Entitled");
            System.Web.UI.WebControls.CheckBox chkbxInvoice = (System.Web.UI.WebControls.CheckBox)item["INCLINV"].FindControl("InclInv");
            RadNumericTextBox txtboxPrice = (RadNumericTextBox)item["alaPrice"].FindControl("alaPrice");


            int service_id = Convert.ToInt32(alaGrid.MasterTableView.DataKeyValues[item.ItemIndex]["service_id"]);
            Boolean oldIchecked = Convert.ToBoolean(alaGrid.MasterTableView.DataKeyValues[item.ItemIndex]["Checked"]);
            double oldPrice = Convert.ToDouble(alaGrid.MasterTableView.DataKeyValues[item.ItemIndex]["Price"]);
            Boolean oldIncludeInvoice = Convert.ToBoolean(alaGrid.MasterTableView.DataKeyValues[item.ItemIndex]["InvoiceChecked"]);


            Boolean entitled = chkbxEntitled.Checked;
            Boolean inclInvoice = chkbxInvoice.Checked;
            double price = Convert.ToDouble(txtboxPrice.Value);

            if (oldIchecked != entitled)
                Insert_update_checkbox(temptablename.Text, TextBoxAdditionalItemsPackageCdAla.Text, service_id, 0, entitled);
            if (oldIncludeInvoice != inclInvoice)
                Insert_update_checkbox(temptablename.Text, TextBoxAdditionalItemsPackageCdAla.Text, service_id, 1, inclInvoice);
            if (oldPrice != price)
                Insert_update_price(temptablename.Text, TextBoxAdditionalItemsPackageCdAla.Text, service_id, price);
        }

        alaGrid.Rebind();
        int updated = Update_User_Calling_StoredProc(tableName, packagecd, sbOrderDetailID, nUserID, sLoginName, sPassword, sEmail, sActive, dblPrice);
        int trying = 0;
         while (updated != 0 && trying++ < 10)
           updated = Update_User_Calling_StoredProc(tableName, packagecd, sbOrderDetailID, nUserID, sLoginName, sPassword, sEmail, sActive, dblPrice);
            

        usersGrid.Rebind();
        DisplayMessage(Session["updateString"].ToString());
        CompanyInfoGrid.Rebind();

    }

........

<telerik:RadGrid ID="usersGrid" runat="server"  AllowPaging="True" PageSize="15"
            DataSourceID="ContentCentralUsers" GridLines="None" Skin="Office2007" AutoGenerateColumns="False"
            ondatabound="usersGrid_DataBound"  AllowFilteringByColumn="True"  
            onitemdatabound="usersGrid_ItemDataBound"   OnItemCreated="usersGrid_ItemCreated"
            onitemevent="usersGrid_ItemDataBound"   
            oniteminserted="usersGrid_ItemInserted" onitemupdated="usersGrid_ItemUpdated"
            ShowStatusBar="True" OnPreRender="usersGrid_PreRender"
            oninsertcommand="usersGrid_InsertCommand" OnItemCommand="usersGrid_ItemCommand"
            onupdatecommand="usersGrid_UpdateCommand"   >
         <ClientSettings>
             <ClientEvents OnCommand="commandClicked" />
        </ClientSettings>
        <PagerStyle Mode="NextPrevAndNumeric" />
        <GroupingSettings CaseSensitive="false" />
     
       <MasterTableView  DataSourceID="ContentCentralUsers"  DataKeyNames="user_id,package_cd" AllowAutomaticDeletes="false"
             AllowFilteringByColumn="True" AllowSorting="True"   AllowAutomaticUpdates="false" AllowAutomaticInserts="false"
              InsertItemPageIndexAction="ShowItemOnFirstPage" CommandItemDisplay="Top"
             NoMasterRecordsText="No users to display.">
            
             <CommandItemTemplate >
               <div style="padding:10px 5px;">
                 <asp:LinkButton  runat="server" id="wizardButton" OnClientClick="openWin('<%# TextBoxOrderDetailID.Text %>'); return false;" >
                        <img style="border:0px;vertical-align:middle;" alt="" src="Img/Wand1.gif" />Add multiple users wizard</asp:LinkButton>
                
                     &nbsp;&nbsp;&nbsp;&nbsp;
                     
                  <asp:LinkButton ID="insertButton" runat="server" CommandName="InitInsert"  >
                        <img style="border:0px;vertical-align:middle;"  alt="" src="Img/AddRecord.gif" /> Add new user</asp:LinkButton>  
                   
                     &nbsp;&nbsp;&nbsp;&nbsp;
                     
                   <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid">
                        <img style="border:0px;vertical-align:middle;" alt="" src="Img/Refresh.gif" /> Refresh</asp:LinkButton>
                   
                </div>
             </CommandItemTemplate>
            <CommandItemSettings AddNewRecordText="Add new user"  />
            
            
            <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
   
            <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
          
   
     <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" AllowFiltering="true" DataField="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"  AllowFiltering="true" DataField="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"  AllowFiltering="true" DataField="package_name">
                      
                        <ItemTemplate>
                            <asp:Label runat="server" ID="Label1" Text='<%#Eval("package_name") %>'></asp:Label><telerik:RadToolTip runat="server" ID="RadToolTip1" TargetControlID="Label1"
                                Skin="Web20" ShowDelay="500" 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"
                            CausesValidation="false"
                            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="75px"  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>
                      <HeaderStyle Width="100px" />
                    
                    </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" />
                         <HeaderStyle Width="100px" />
                      </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>   
          
          
           <telerik:GridTemplateColumn EditFormHeaderTextFormat=""  HeaderStyle-VerticalAlign="Top" Visible="false">
             <EditItemTemplate>
               <telerik:RadGrid ID="PackageReadOnlyGrid" runat="server" AutoGenerateColumns="False" Visible="false"
                             DataSourceID="spAddNewsTradeProduct" GridLines="None" Skin="Office2007"
                             onitemdatabound="PackageReadOnlyGrid_ItemDataBound"
                             ShowStatusBar="True"
                             OnPreRender="PackageReadOnlyGrid_PreRender" >
                 <MasterTableView CommandItemDisplay="None" >     
                    <Columns>
                       <telerik:GridBoundColumn HeaderText="Service ID" 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:GridCheckBoxColumn HeaderText="Purchased" UniqueName="CHECKED" DataField="Checked" EditFormColumnIndex="1">
                       </telerik:GridCheckboxColumn >
                       <telerik:GridMaskedColumn  DataField="Price"  Mask="$ #####.##" DataFormatString="{0:C2}" HeaderText="Price" Display="false" UniqueName="Price"
                                  EditFormColumnIndex="2"     >
                         <ItemStyle HorizontalAlign="Right" />
                      </telerik:GridMaskedColumn>
                       </Columns>
                     <EditFormSettings ColumnNumber="5">
                     </EditFormSettings>
                     <PagerStyle AlwaysVisible="True" />                          
                    </MasterTableView>
                 </telerik:RadGrid>                    
              </EditItemTemplate>
             <HeaderStyle VerticalAlign="Top"></HeaderStyle>
          </telerik:GridTemplateColumn>
        
        <telerik:GridTemplateColumn EditFormHeaderTextFormat=""  HeaderStyle-VerticalAlign="Top" Visible="false" EditFormColumnIndex="1" UniqueName="AlaCartePriceGrid">
           <EditItemTemplate>
               <telerik:RadGrid ID="AlaCartePriceGrid" runat="server" AutoGenerateColumns="False"
                             DataSourceID="spAddNewsTradeProductAlaCarte" GridLines="None" Skin="Office2007"  OnItemCommand="AlaCartePriceGrid_ItemCommand"
                             onitemdatabound="AlaCartePriceGrid_ItemDataBound"
                             ShowStatusBar="True" OnPreRender="AlaCartePriceGrid_PreRender" >
                 <MasterTableView CommandItemDisplay="None"  EditMode="InPlace" DataKeyNames="service_id,Price,Checked,InvoiceChecked" >     
                    <Columns>
                         <telerik:GridBoundColumn HeaderText="Service ID" UniqueName="service_id" DataField="service_id" ReadOnly="true"
                          Visible="false" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="service_name" HeaderText="Available a la carte Content" Display="true"   ReadOnly="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 HeaderText="Price" UniqueName="alaPrice">
                           <ItemTemplate>
                                  <telerik:RadNumericTextBox ID="alaPrice" runat="server"  Price='<%# Eval("Price") %>'
                                    Culture="English (United States)" Type="Currency"   DbValue='<%# DataBinder.Eval(Container.DataItem, "Price") %>'  
                                      Width="125px">  
                                  </telerik:RadNumericTextBox>
                               </ItemTemplate>
                         </telerik:GridTemplateColumn>
                         <telerik:GridTemplateColumn HeaderText="Inv. Disp" UniqueName="INCLINV">
                        <ItemTemplate>
                          <asp:CheckBox ID="InclInv"  Checked='<%# Eval("InvoiceChecked") %>' runat="server" />
                                 </ItemTemplate>
                          </telerik:GridTemplateColumn>
                       </Columns>
                    </MasterTableView>
                 </telerik:RadGrid>                    
              </EditItemTemplate>

             <HeaderStyle VerticalAlign="Top"></HeaderStyle>
           </telerik:GridTemplateColumn>   
          
           <telerik:GridTemplateColumn EditFormHeaderTextFormat=""  HeaderStyle-VerticalAlign="Top" Visible="false" EditFormColumnIndex="1">
           <EditItemTemplate>

2 Answers, 1 is accepted

Sort by
0
Laura
Top achievements
Rank 1
answered on 14 Nov 2008, 01:55 PM
Just to add to this...it appears it cannot find any template columns in the updatecommand procedure. I have also submitted a support ticket for this as it is important I get this working.
0
Iana Tsolova
Telerik team
answered on 17 Nov 2008, 12:07 PM
Hello Laura,

I followed your scenario and prepared a sample project for you. Please try it on your end and let me know if it works as desired and what differs in your case.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Laura
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or