Home  |  Contact us    
Setting Focus on ASP.NET control


How to set the Focus on control in ASP.NET?

In earlier versions of ASP.NET, assigning focus to a control involves writing client-side script (such as JavaScript). In ASP.NET 2.0, this process has been much simplified, and you can now set the focus of a control via its Focus() method. Like

txtName.Focus();

You can also set the focus of a control through the SetFocus( ) method of the Page class. The syntax is:

Page.SetFocus(controlName);

Apart from this you can use defaultfocus attribute to set the control that will be assigned the focus when the form is loaded.
< form id="form1" runat="server"
defaultfocus="txtEmail"
>



Category: ASP.NET 2.0 Faqs, Interview Questions & Answers



Ask New Questions
Microsoft.Net Framework
.Net 2.0 Namespaces
.Net Assemblies
OOPS Faqs in C#
ASP.Net Faqs
ASP.Net 2.0 Faqs
Web Services Faqs
ADO.Net Faqs
Database Faqs
OOPS Faqs
IT Project Management