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

Set focus to another control once clientside or serverside event completes

1 Answer 153 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ali Mohamad
Top achievements
Rank 1
Ali Mohamad asked on 09 Aug 2012, 06:23 PM
Hi,
I have a page where several controls including a combobox are dynamically created within a Ajax panel.  The combobox control has an serverside event that handles the "SelectedIndexChanged" event, within which I enable/disable other controls based on the selected value. 

The Problem:
The problem is that the browser sets the cursor back to the first form field losing the focus from the combobox.

Needed Behaviour:
What I need to do is to NOT lose the TAB sequence so that the user can continue tabbing through to the next field on the page.

What I tried:
I tried setting focus on the combobox in the serverside event handler which does not seem to work.  I then tried setting the focus on the combobox in the client-side "OnResponseEnd" event handler for the RadAjaxManager but that does not work either.  I then tried setting the focus in the client-side "OnClientSelectedIndexChanged" event handler for the combobox and this too does not work.

What can I do to set the focus back to the combobox after an item is selected and the server-side "SelectedIndexChanged" event handler completes?

Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Aug 2012, 09:34 AM
Hi,

One suggestion is that you can keep track of the state using a hiddenfield and set focus in OnClientLoad event of RadCombobox based on hiddenfield value as follows. 

ASPX:
<telerik:RadComboBox ID="RadComboBox1" EmptyMessage="tab" runat="server" OnClientLoad="OnClientLoad"
            AutoPostBack="true" onselectedindexchanged="RadComboBox1_SelectedIndexChanged" >
  <Items>
        .................................
  </Items>
</telerik:RadComboBox>
<asp:HiddenField ID="HiddenField1" runat="server" />

C#:
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
 {
   HiddenField1.Value = "1";
 }

Javascript:
function OnClientLoad()
{
 var hid = document.getElementById("HiddenField1");
 if (hid.value == 1)
 {
  hid.value = "";
  $("#RadComboBox1_Input").focus();
 }
}

Thanks,
Princy.
Tags
ComboBox
Asked by
Ali Mohamad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or