cannot set focus to grid from client side javascript

4 posts, 0 answers
  1. EJ
    EJ avatar
    39 posts
    Member since:
    Jun 2012

    Posted 21 Jun 2010 Link to this post

    I'm trying to figure out how to set the focus from outside of the grid to a particular radnumerictextbox editor cell in the grid (the whole radgrid is in edit mode) from client side using javascript. it says there is no method called focus() on the grid

    <script type="text/javascript"
                        function gotoGrid() { 
                                var grid = $find('MainContent_GeneralControl_MyFormView_MyRadGrid'); 
                                if (grid != null) { 
                                    grid.set_focus(); // this says there is no such method 
                                } 
                            } 
                    </script> 
     

    this code is being fired from an onblur event in a radnumerictextbox
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Jun 2010 Link to this post

    Hello,

    I suppose your scenario is, you need to focus to RadNumericTextBox placed in EditItemTemplate of grid in the OnBlur event of another RadNumericTextBox which is outside grid. Here is same scenario and code for focusing to textbox from client side.

    ASPX:
       . . . . . . . . . . . . . 
             <EditItemTemplate>  
                 <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">  
                 </telerik:RadNumericTextBox>  
             </EditItemTemplate>  
          </telerik:GridTemplateColumn> 
       </Columns> 
     </MasterTableView> 
    </telerik:RadGrid> 
      
     <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">  
       <ClientEvents OnBlur="gotoGrid" />  
     </telerik:RadNumericTextBox> 
     

    Java Script:
    <script type="text/javascript"
        function gotoGrid()  
        { 
            var grid = $find("<%=RadGrid1.ClientID %>"); 
            if (grid != null
              { 
                var MasterTable = grid.get_masterTableView(); 
                var NumericTextBox = MasterTable.get_dataItems()[0].findControl("RadNumericTextBox1"); 
                NumericTextBox.focus(); 
              } 
        }  
    </script> 
     

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. EJ
    EJ avatar
    39 posts
    Member since:
    Jun 2012

    Posted 24 Jun 2010 Link to this post

    i do not have a template column - it is a rgridnumericcolumn which renders a radnumerictextbox i think - so this does not work for the situation

    but it does not solve my larger problem. it does indeed set the focus to the grid but then the partial postback occurs and afterward i loose the focus to the grid

    it seems that whenever I have a partial postback of my page (radcombobox text_changed for example) that after the postback i loose the focus of what my cursor was on - how to I keep my focus - i've been trying to have javascript client side code onblur and onfocus and onkeydown keep track of what key was pressed and if it was tab then set focus to the next one or if shift tab then set focus to the prior one
  5. Daniel Aquere
    Daniel Aquere avatar
    85 posts
    Member since:
    Mar 2011

    Posted 26 Jul 2011 Link to this post

    Hi Princy and EJ,

    I´m receiving this error message: "Microsoft JScript runtime error: Unable to get value of the property 'focus': object is null or undefined"

    when executes this command line "NumericTextBox.focus(); " 

    Please, what can be?

    Thanks, best

    Daniel
Back to Top