Client-side focus on RadComboBox

6 posts, 1 answers
  1. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 07 Jun 2010 Link to this post

    Hi:

    I am trying not to hard code the combo-box that I would like to set focus, so I am passing in the client id.
    <script type="text/javascript"
        function SetComboBoxFocus(clientId) { 
            var comboBox = $find(clientId); 
            var input = comboBox.get_inputDomElement(); 
            input.focus(); 
            return false; 
        } 
    </script>  
     

    My server side code is:
    Dim _radComboBox As RadComboBox = RadComboBox1 
    If CheckBox1.Checked Then 
        _radComboBox = RadComboBox2 
    End If 
    ScriptManager.RegisterStartupScript(Me, Me.GetType, "inlinesetfocus", "SetComboBoxFocus('" & _radComboBox.ClientID & "');", True) 
     

    The javascript code is not finding the combo-box control.  Any suggestions?

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

    Posted 08 Jun 2010 Link to this post

    Hi Phil,

    Modify the code as shown below and check whether its workign as expected.

    server code:
     
    ScriptManager.RegisterStartupScript(MeMe.[GetType](), "inlinesetfocus""function f() { SetComboBoxFocus('" & _radComboBox.ClientID & "'); Sys.Application.remove_load(f);} Sys.Application.add_load(f); "True)  
     

    Regards,
    Princy.
  3. Answer
    Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 08 Jun 2010 Link to this post

    Hi Phil,

    I guess you are using this help topic as a reference.
    Finding a control this way
     
    var comboBox = $find("<%=RadComboBox1.ClientID %>");

    is not a hard-coding. This is the right way to get the client object of the RadComboBox.

    Best wishes,
    Veronica Milcheva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  4. T. Tsonev
    Admin
    T. Tsonev avatar
    2815 posts

    Posted 08 Jun 2010 Link to this post

    Hello Princy,


    Sincerely yours,
    Tsvetomir Tsonev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 08 Jun 2010 Link to this post

    Hi Veronica & Princy:

    So, in this situation I have two different dropdowns that conditionally need to have focus set.  In addition, I have been known to place such scripts in the master page, thusly the script is available for all pages that use the master page.

    Phil


  6. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 09 Jun 2010 Link to this post

    Hi Veronica & Princy:

    I have created the following sample:
    <%@ Page Language="VB" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <script runat="server"
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
            CheckBox_SetFocus() 
        End Sub 
        Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) 
            CheckBox_SetFocus() 
        End Sub 
        Protected Sub CheckBox_SetFocus() 
            Dim _radComboBox As RadComboBox = NumRadComboBox 
            If CheckBox1.Checked Then 
                _radComboBox = AlphaRadComboBox 
            End If 
            ScriptManager.RegisterStartupScript(Me, Me.GetType, "inlinesetfocus", "function f() { SetComboBoxFocus('" & _radComboBox.ClientID & "'); Sys.Application.remove_load(f);} Sys.Application.add_load(f); ", True) 
        End Sub 
    </script> 
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
    </head> 
    <body> 
        <script type="text/javascript"
            function SetComboBoxFocus(clientId) { 
                $find(clientId).get_inputDomElement().focus(); 
            } 
        </script>  
        <form id="form1" runat="server"
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" > 
            </telerik:RadScriptManager> 
            <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" /> 
            <telerik:RadComboBox ID="NumRadComboBox" runat="server"  
                MarkFirstMatch="True" 
                > 
                <Items> 
                    <telerik:RadComboBoxItem Value="0" Text="0 - Zero" Selected="True" /> 
                    <telerik:RadComboBoxItem Value="1" Text="1 - One" /> 
                    <telerik:RadComboBoxItem Value="2" Text="2 - Two" /> 
                    <telerik:RadComboBoxItem Value="3" Text="3 - Three" /> 
                </Items> 
            </telerik:RadComboBox> 
            <telerik:RadComboBox ID="AlphaRadComboBox" runat="server"  
                MarkFirstMatch="True" 
                > 
                <Items> 
                    <telerik:RadComboBoxItem Value="A" Text="A" Selected="True" /> 
                    <telerik:RadComboBoxItem Value="B" Text="B" /> 
                    <telerik:RadComboBoxItem Value="C" Text="C" /> 
                    <telerik:RadComboBoxItem Value="D" Text="D" /> 
                </Items> 
            </telerik:RadComboBox> 
        </form> 
    </body> 
    </html> 
     

    I do not know what embedding the call to the js SetComboBoxFocus function does, but it works.

    Thanks Phil
    PS  the
    ScriptManager1.SetFocus(NumRadComboBox.ClientID + "_Input") 
     
    also works fine.

Back to Top