How to set focus on control using javascript

This article demonstrates how to set focus to an ASP.NET Web Form control by using client-side script.

ASP.NET Web Form controls provide a similar look and feel of the traditional HTML controls while they provide a consistent and structured interface and more robust features. In addition, you can use client-side scripting to enhance the functionality that these controls provide.

In my project, i required to set focus on particular control on the drop down change event. For this i used/added following javascript on the SelectedIndexChanged event of drop down list:

Page.RegisterStartupScript("MoveVerticalScrollBar", "<script>document.all('" + chkEmployee.ClientID + "').focus();</script>");

With the help of above script, focus set to
chkEmployee control after the SelectedIndexChanged event of drop down list.

Post a Comment

Previous Post Next Post