You are here:

Active Server Pages Programming (ASP)/Move focus by pressing enter key in ASP.NET 2.0 Web Form

Advertisement


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  

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


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.

©2012 About.com, a part of The New York Times Company. All rights reserved.