Set focus on ComboBox on Page Load

I have a page that starts off with a ComboBox, and I need focus to go into that combobox automatically when the page loads so that the user does not have to initiate a mouse click.

My ComboBox looks like this:





I tried this to set the focus into it on page load:

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.ComboBox1.Focus()
        End If
    End Sub

And I also tried a javascript approach like this:


But nothing has worked. What am I missing?

Thanks in advance,

Jon

3 Replies 1 reply marked as answer

MK Muthukrishnan Kandasamy Syncfusion Team July 10, 2020 03:47 PM UTC

 
Hi Jon, 
 
Thanks for contacting Syncfusion support. 
 
We have validated your requirements in Syncfusion EJ ComboBox control. We can focus the ComboBox control on the initial page loading time. We have found that in your shared code you have used direct id of ComboBox control to focus the control. In ASP.NET Web Forms controls Id will be changed so that we need use ClientID to get the element. Please refer the below code block for focusing the ComboBox control. 
 
<script type="text/javascript"> 
        $(function () { 
            $("#<%=ComboBox1.ClientID%>").focus(function () { 
                console.log("focused!!!"); 
            }); 
           $("#<%=ComboBox1.ClientID%>").focus(); 
        }); 
</script> 
 
 
Description 
Link 
Getting started 
Data binding 
Accessibility 
API reference 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Muthukrishnan K 


Marked as answer

JO Jon July 10, 2020 08:14 PM UTC

There you go, that worked! Thank you very much!


MK Muthukrishnan Kandasamy Syncfusion Team July 13, 2020 04:15 AM UTC

 
Hi Jon, 
 
Thanks for your update. 
 
We are glad to know that given solution works. Please let us know if you need any further assistance. 
 
Regards, 
Muthukrishnan K 


Loader.
Up arrow icon