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

Client-side focus on RadComboBox

5 Answers 332 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 2
Phil asked on 07 Jun 2010, 05:58 PM
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

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jun 2010, 11:14 AM
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.
0
Accepted
Veronica
Telerik team
answered on 08 Jun 2010, 11:36 AM
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.
0
T. Tsonev
Telerik team
answered on 08 Jun 2010, 11:44 AM
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.
0
Phil
Top achievements
Rank 2
answered on 08 Jun 2010, 04:58 PM
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


0
Phil
Top achievements
Rank 2
answered on 09 Jun 2010, 05:59 PM
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.

Tags
ComboBox
Asked by
Phil
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Veronica
Telerik team
T. Tsonev
Telerik team
Phil
Top achievements
Rank 2
Share this question
or