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

Focus Lost on partial post back.

1 Answer 109 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 02 Jul 2013, 07:45 PM
I have a bunch of controls inside a RadAjaxPanel.
Some of the controls have auto post back set to true and populate other controls on the page.

When the post back occurs, all focus is lost (pressing tab one time selects the first control on the page).
I tried to fix using the following javascript which I found online: (I put the below inside the Selected IndexChanged event for one of the controls that causes the post back).

Dim sm As ScriptManager = ScriptManager.GetCurrent(Me)

sm.SetFocus(ddl_Category.ClientID)

The good news is that it works momentarily, I can see focus jump to this control (which happens to be on another part of the page but within the same RadAjaxPanel) and can even get a couple of characters to type if I'm fast.  But within less than a second the focus is lost and pressing tab goes to the first control on the page.

I don't know where to even start looking to resolve this issue.  I've tried many different methods to try and set focus to the control thinking they weren't working - when I realized that they actually were working they just got overrode a second later I got stuck.

Thanks,

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 05 Jul 2013, 10:11 AM
Hi Robert,

In order to focus a control on postback request you could use the FocusControl() method of RadAjaxPanel. For example if you have two RadComboBox controls in a RadAjaxPanel you could use the OnSelectedIndexChanged event of the first RadComboBox and on postback focus the second one. The event handler would look similar to the one below:

Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    RadAjaxPanel1.FocusControl(RadComboBox2)
End Sub

Try this approach and you should be able to focus the control you want on postback.

Regards,
Viktor Tachev
Telerik
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 the blog feed now.
Tags
General Discussions
Asked by
Robert
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or