Setting Focus IE/FF

3 posts, 0 answers
  1. Declan
    Declan  avatar
    47 posts
    Member since:
    May 2007

    Posted 17 Nov 2008 Link to this post

    The following works just fine in FireFox to set focus to a text box when the form is in edit mode:

    Private Sub grd_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grd.ItemDataBound 
    If (TypeOf (e.Item) Is GridEditFormItem) AndAlso e.Item.IsInEditMode Then 
    Dim box As TextBox = e.Item.FindControl("ContactName"
    grd.ClientSettings.ClientEvents.OnRowCreated = String.Format("document.getElementById('{0}').focus()", box.ClientID) 

    In IE I get an error:

    Sys.InvalidOperationException: Handler must be a function.

    function Sys$Component$_setReferences(component, references) { 
     ... other code here ... 
        if (events) { 
            for (var name in events) { 
                if (!(component["add_" + name] instanceof Function)) throw new Error.invalidOperation(String.format(Sys.Res.undefinedEvent, name)); 
                if (!(events[name] instanceof Function)) throw new Error.invalidOperation(Sys.Res.eventHandlerNotFunction); 
                component["add_" + name](events[name]); 

    The var name contains "rowCreated" suggesting that IE doesn't like "document.getElementById('{0}').focus()"

    I have also tried inserting a function call here with a function in the ascx. This works in FF but, yet again not in IE.

    I have read a lot of posts on this subject and tried many without success. IE seems to be the difficulty as it works in FF, Safari and Chrome.

    All I want to do is setfocus to a text box when the grid enters edit mode. Not that I think this should be a problem but I am using dynamically loaded ascx controls running in DotNetNuke.


  2. Nikolay Rusev
    Nikolay Rusev avatar
    2276 posts

    Posted 20 Nov 2008 Link to this post

    Hello Declan ,

    You have 3 options to achieve this functionality:

    1. Enable RadGrid.KeyboardNavigation - thus when item enter in edit mode first editable control in the current EditForm will be focused. You should enable the following settings:
    <ClientSettings AllowKeyboardNavigation="true">  

    2. On RadGrid.ItemDataBound event  use this code:
    void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
                TextBox control = ((GridTextBoxColumnEditor)((GridEditFormItem)e.Item).EditManager.GetColumnEditor("ShipName")).TextBoxControl;  
    3. If both approaches above doesn't help you can try this one:
        void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
                TextBox control = ((GridTextBoxColumnEditor)((GridEditFormItem)e.Item).EditManager.GetColumnEditor("ShipName")).TextBoxControl;  
                StringBuilder script = new StringBuilder();  
                script.AppendFormat(@"$get('{0}').focus();", control.ClientID);  
                RadGrid2.ClientSettings.ClientEvents.OnGridCreated = script.ToString();  

    I hope this was helpful.

    Kind regards,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft R3 2016 release webinar banner
  4. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 04 May 2009 Link to this post

    try this 


    if (e.Item.OwnerTableView.Name == "gvVendor" && e.Item is GridEditFormItem && e.Item.IsInEditMode)




    TextBox txtVendorName = (TextBox)e.Item.FindControl("txtVendorName");





    else if (e.Item.OwnerTableView.Name == "gvProducts" && e.Item is GridEditFormItem && e.Item.IsInEditMode)




    TextBox txtswName = e.Item.FindControl("txtswName") as TextBox;




Back to Top