Set focus to another control once clientside or serverside event completes

2 posts, 0 answers
  1. Ali Mohamad
    Ali Mohamad avatar
    15 posts
    Member since:
    Oct 2009

    Posted 09 Aug 2012 Link to this post

    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?

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

    Posted 10 Aug 2012 Link to this post


    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. 

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

    protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
       HiddenField1.Value = "1";

    function OnClientLoad()
     var hid = document.getElementById("HiddenField1");
     if (hid.value == 1)
      hid.value = "";

Back to Top