Focus edit item template items

4 posts, 0 answers
  1. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 05 Feb 2013 Link to this post

    Hi,
    How to set focus to telerik rad date picker, that resides in telerik rad grid as edit item template using javascript?.

    Thanks & Regards
    Anzar.M
    Software Engineer
    SBN // Technologics
    Ernakulam. 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Feb 2013 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                GridEditFormItem item = (GridEditFormItem)e.Item;
                RadDatePicker pkr1 = (RadDatePicker)item.FindControl("RadDatePicker1");
                RadGrid1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['pkr'] = '" + pkr1.ClientID + "';</script>"));
            }
    }
    JS:
    $(document).ready(function () {
         var pkr = $find(window['pkr']);
            pkr.get_dateInput().focus();
        });

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 05 Feb 2013 Link to this post

    Hi Princy,
    This is not working. Please provide another solution.

    Thanks & Regards
    Anzar.M
    Software Engineer
    SBN // Technologics
    Ernakulam.
  5. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 08 Feb 2013 Link to this post

    Hello Anzar,

    The RadDatePicker is a special case because it has two editor control and you could not call just the focus() function. You need to be more specific which element you want to focus.

    Please check out the attached web site which demonstrates two approaches, one to show directly the RadDatePicker popup so the user is able to choose directly the date. And in the commented section you could use the code to focus the Dateinput so the user is able to type the date by itself.

    You can use the following topic to access the generated picker in edit mode:
    ( Section Accessing controls in edit/insert mode )
    http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

    I hope this helps. Please give it a try and let me know about the result.

    All the best,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top