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

cannot set focus to grid from client side javascript

3 Answers 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
EJ
Top achievements
Rank 1
EJ asked on 21 Jun 2010, 10:04 PM
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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Jun 2010, 07:01 AM
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.
0
EJ
Top achievements
Rank 1
answered on 24 Jun 2010, 12:19 PM
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
0
Daniel Aquere
Top achievements
Rank 2
answered on 27 Jul 2011, 02:31 AM
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
Tags
Grid
Asked by
EJ
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
EJ
Top achievements
Rank 1
Daniel Aquere
Top achievements
Rank 2
Share this question
or