AllExperts > Experts 
Search      
Active Server Pages Programming (ASP)
Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ujjwal
Expertise
Six ASP Objects, ASP and Database Coding, Stored Procedure, EMail, Printing in ASP, VBScript, WebServer(IIS) Configuration, Active X Programming, Session Variable, Application Variables, Cookies, Global.ASA

Experience
ASP, COM, SQL SERVER 2000, .NET, SMS, MOM, Crstal Reports, MsProject, BizTalk Serve, Sharepoint Portal Server, Oracle D2K

 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > ASP.net Focus

Active Server Pages Programming (ASP) - ASP.net Focus


Expert: Ujjwal - 12/6/2004

Question
How do I automatically set the focus on a asp.net page to a text box when the page loads?

Also how do I launch a command button such as search or submit when the enter button is pressed on a keyboard?

Answer
IN C#, for Set focus try this:

1) In the Form.Load event handler, write: this.ActiveControl = txtInput;
2) In the Form.Activate event handler, write:
txtInput.Focus();

In ASPX file, your code should be for Launching a command button when enter button is pressed:

<body onkeydown="if (event.keyCode == 13){event.returnValue = false;  event.cancel = true; document.getElementById('btnSearch').click();}" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">



Regards  

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.