Click here to Skip to main content
14,599,574 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello!!!

I am developing a web page in VB.net.
On hitting the enter button I want to focus on the next item.

In VB6 there are events like Keypress/Keyup/Keydown/gotfocus etc..

I am unable to find such events in VB.net.

How can I use the enter key to navigate?

Thanks!!!

Ernest
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 3

Here: MSDN: Control.OnKeyPress Method [^]

You would need to override OnKeyPress, something like (C# version - I am little quick with pseudocode in C#):
protected override void OnKeyPress(KeyPressEventArgs e)
{
        if (e.KeyCode == Keys.Enter)
        {
            // Do whatever you want
            e.Handled = true;
            //SendKeys.Send("{TAB}");
        }
}


All the events of Button: MSDN: Button Events[^]
   
v3
Comments
ernestmachado 23-Apr-12 0:11am
   
Thank you Sandeep for the code and link.
I tried your code but it is not recognizing the KeyPressEventArgs e argument.
Is any name space needs to be included.
Sandeep Mewara 23-Apr-12 3:12am
   
Did you go through the MSDN links and followed it?
Mehdi Gholam 23-Apr-12 2:35am
   
The OP is looking for VB.net :)
Sandeep Mewara 23-Apr-12 3:12am
   
I know. I already wrote in my answer that I was/am quick with my C# pseducode so wrote that. Gave a full reference of the MSDN links where VB.NET exampled and explanations are there.

:)
ernestmachado 23-Apr-12 3:20am
   
Yea I did go through the MSDN Button events.
When it comes to Control.OnKeyPress Method, I am unable to get the System.Windows.Forms namespace. I guess I'm seariously going off track.

First of all I want some clarify that I am doing a vb.net web project and not an application.
Has the System.Windows.Forms namespace has to do something related to web applications only and not web project?
Is it that some facilities present in VB6 are available for web applications only and not web project?
Sandeep Mewara 23-Apr-12 4:54am
   
There you go! All the while we were trying to help you for a Winform app. This is what happens if you don't frame your question properly and tag it correctly! :doh:

For web project, the onkeypressis not a server event and you need to add that as an attribute event or use a HTML control that does expose that event. try out.
ernestmachado 23-Apr-12 3:23am
   
I did try to do it using javascript but that too is not working consistantly?
Can you advice any wayout for this using any other alternate method like javascript?
ernestmachado 23-Apr-12 5:12am
   
Thankfully I realised that you'll are taking it the other way at this point.
I thought mentioning 'web page' in my question would be sufficient.

Atlease I'm on the track now.

Thank you so much for the input.

I did try with the HTML attributs but it is still not working as expected. The navigation is working properly only when the user changes the text else it doesn't work.

need a solution where in the navigation works smoothly just by ENTER key.
Sandeep Mewara 23-Apr-12 5:42am
   
Try: onkeydown="javascript:if(event.keyCode==13){event.keyCode=9;}" in the HTML input control.
ernestmachado 26-Apr-12 2:54am
   
This code works absolutely fine.
Sandeep Mewara 26-Apr-12 4:39am
   
Good to know. You should mark the answer resolved to help others in future. :thumbsup:
ernestmachado 23-Apr-12 8:13am
   
I did try that but as I mentioned it is not navigating if the user doesn't change the text. I'm working on it to solve the same.
Prasad_Kulkarni 28-Apr-12 0:12am
   
Nice explanation Sandeep, +5!
Rate this:
Please Sign up or sign in to vote.

Solution 2

VB.Net has events similar to VB. Check out http://msdn.microsoft.com/en-us/library/system.windows.forms.button.aspx[^] (scroll down towards the middle of the page).
   
Comments
ernestmachado 23-Apr-12 0:07am
   
Thank you for the link. But I'm still unable to get the event I need.
VJ Reddy 23-Apr-12 19:47pm
   
Good reference. 5!
Abhinav S 23-Apr-12 23:15pm
   
Thanks.
Prasad_Kulkarni 28-Apr-12 0:13am
   
Good links Abhinav +5!
Abhinav S 28-Apr-12 0:44am
   
Thanks.
Rate this:
Please Sign up or sign in to vote.

Solution 1

These events are on each control, just select the control you need (e.g. textbox1) and in the properties you will find the events.
   
Comments
ernestmachado 23-Apr-12 0:03am
   
Thank you for your reply.
I checked in the event list of a text box but events I want are not appearing.
Do we need to import any specific namespace?
Mehdi Gholam 23-Apr-12 2:34am
   
All events are displayed there, so you don't have to do anything.

What event are you looking for?
Rate this:
Please Sign up or sign in to vote.

Solution 4

Of course VB.NET also has those events. Look at the 2 drop down menus at the top of the coding area. Left menu to select the control and the right one to choose the event.
   
Comments
ernestmachado 23-Apr-12 0:08am
   
Thank you for your reply. I did try that before positing the question.
Rate this:
Please Sign up or sign in to vote.

Solution 5

Please check Solution 3 for detail solution.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100