Focus on control in item template

3 posts, 1 answers
  1. Gavin
    Gavin avatar
    31 posts
    Member since:
    Sep 2012

    Posted 20 Aug 2012 Link to this post

    Hi,

    I am trying to use the below code to focus on a RadNumericTextBox contained within the item template of a panel bar item when the item expands.

    The javascript finds the control correctly but the focus call does nothing.  Can anyone please give me any info on why the focus does not land in the control?

    Thanks

    Gavin.

    function OnItemExpand(sender, args)
    {
        var itm = args.get_item();
        if (itm.get_value() == "9")
        {
            var ctrl = itm.findControl("txtEpiID");
            if (ctrl != null)
            {
                ctrl.focus();
            }
        }
    }

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Aug 2012 Link to this post

    Hi Gavin,

    Here is the sample code that I tried to set focus in NumericTextBox on expanding.
    JS:
    function OnClientItemExpand(sender, args)
     {
         var item = sender.findItemByValue("9");
         var txt = item.findControl("txtEpiID");
         window.setTimeout(function () { txt.focus(); }, 20);
    }
    Also check the following help documentation which explains accessing controls from client side.
    Accessing Controls Inside Templates.

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

    Posted 23 Aug 2012 Link to this post

    Thanks Princy,

    This worked, though I had to change the timout to 500 as that the expansion is completed before setting focus.

    cheers

    Gavin.

Back to Top