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 Srini Nagarajan
Expertise
I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience
Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.
 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > Move focus by pressing enter key in ASP.NET 2.0 Web Form

Topic: Active Server Pages Programming (ASP)



Expert: Srini Nagarajan
Date: 2/11/2008
Subject: Move focus by pressing enter key in ASP.NET 2.0 Web Form

Question
Hi

This is Yogesh and while searching on net I came across a question posted here

http://en.allexperts.com/q/Active-Server-Pages-1452/Pressing-Enter-Key.htm

Solution is also there posted by you
I tried using it in my ASP.Net 2.0 web form text boxes but my focus never gets shifted to next text box. Also whenever I say autopostback=true it submits it to server and don’t move the focus. Where should i put this script. In page load, Java Script etc.


If you have got any solution to this problem, Can you please send the sample code or some snippet?

Thanks and regards


Answer
hi

You need to handle thru javascript

give a try something like this


txtBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + txtBox2.UniqueID + "').focus();return false;}} else {return true}; ");

txtBox2.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + txtBox3.UniqueID + "').focus();return false;}} else {return true}; ");

etc...

Not tested may need some tweaks..

-Srini  

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.