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

Focus on control in item template

2 Answers 34 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Gavin
Top achievements
Rank 1
Gavin asked on 20 Aug 2012, 05:44 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Aug 2012, 07:51 AM
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.
0
Gavin
Top achievements
Rank 1
answered on 24 Aug 2012, 01:45 AM

Thanks Princy,

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

cheers

Gavin.

Tags
PanelBar
Asked by
Gavin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Gavin
Top achievements
Rank 1
Share this question
or