keyDown

  • Thread starter Thread starter Anne
  • Start date Start date
A

Anne

hie again, i have 3 textbox and i would like the user to
go to the next textbox by pressing the 'ENTER' key. i have
tried using this:

Private Sub txtRequestor_KeyDown(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles
txtRequestor.KeyDown
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
End Sub

The coding produces these errors:
1. Event 'keyDown' cannot be found
2. Name 'Keys' is not declared
3. Name 'SendKeys' is not declared

what us the cause of my problem? do i have to add in other
reference (i have already added System.Windows.Forms) so
that the keyDown event can be found? or is there another
way to do this?

Thanx!
 
he must be using a BROWSER!

there is no such event for a text box in Asp.Net.

and the reference to SYSTEM.WINDOWS.FORMS is really puzzling. Is this a WEB
project (that's what this N.G. is for) or is this a desk-top application?
 
Hi Anne,

Yes, there is an onkeydown event for a text box. However, it is not on the
server side. It is on the client side, in the browser. The problem is that
you can't send keys through the browser interface programmatically. It just
isn't safe, and I don't expect that you ever will be able to. A hostile web
site could type any combination of keys on a client computer if that was so.

I mistakenly thought that you had written a client-side event handler there,
as it looks a lot like one for Internet Explorer (should have looked more
carefully). If this is a server-side event handler, you're barking way up
the wrong tree there. The good news is, you can get the effect you want on
the client side without a PostBack, and without having to use the client
keyboard. While the TAB key moves the focus to the next form field in most
browsers, you can use the JavaScript focus() method to set the focus on any
form element you wish. So, what you really need is a client-side event
handler that captures the ENTER key and sets the focus on the form element
you desire. However, be advised that this is not standard browser behavior,
and therefore may be contrary to the way that people expect their browser to
behave. Here is an example:

<script type="text/javascript"><!--
function GetEnter()
{
if (event.keyCode == 13) document.forms[0].elementName.focus();
}
// --></script>

"elementName" is the name attribute of the form element you want to shift
the focus to.

In Your textbox, just add an "onkeydown" event handler. Example:

<input type="text" name="myText" size="20" onkeydown="GetEnter()">

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.
 
hie kevin,
thanx 4 the reply, and yes, at the time i was reading ur
explanation and solution, i was able to find another
solution similar to yours using javascript :) thanx once
again!
-----Original Message-----
Hi Anne,

Yes, there is an onkeydown event for a text box. However, it is not on the
server side. It is on the client side, in the browser. The problem is that
you can't send keys through the browser interface programmatically. It just
isn't safe, and I don't expect that you ever will be able to. A hostile web
site could type any combination of keys on a client computer if that was so.

I mistakenly thought that you had written a client-side event handler there,
as it looks a lot like one for Internet Explorer (should have looked more
carefully). If this is a server-side event handler, you're barking way up
the wrong tree there. The good news is, you can get the effect you want on
the client side without a PostBack, and without having to use the client
keyboard. While the TAB key moves the focus to the next form field in most
browsers, you can use the JavaScript focus() method to set the focus on any
form element you wish. So, what you really need is a client-side event
handler that captures the ENTER key and sets the focus on the form element
you desire. However, be advised that this is not standard browser behavior,
and therefore may be contrary to the way that people expect their browser to
behave. Here is an example:

<script type="text/javascript"><!--
function GetEnter()
{
if (event.keyCode == 13) document.forms [0].elementName.focus();
}
// --></script>

"elementName" is the name attribute of the form element you want to shift
the focus to.

In Your textbox, just add an "onkeydown" event handler. Example:

<input type="text" name="myText" size="20" onkeydown="GetEnter()">

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.

Anne said:
hie david, yes, this is a web project. but i am trying 2
integrate that keyDown event from the system.windows.forms.
are u sure there's no such thing for a textbox in asp.net?
anybody else have any idea on how i can use similar
function as the keyDown?

thanx 4 all the help!
desk-
top application? in
message user
to key. i
have in
other System.Windows.Forms)
so


.
 
Back
Top