By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

keyDown

P: n/a
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!

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You must not be using Internet Explorer for your browser.

HTH,

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

"Anne" <li*******@yahoo.com> wrote in message
news:03****************************@phx.gbl...
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!

Nov 17 '05 #2

P: n/a
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?

"Kevin Spencer" <ke***@SPAMMERSSUCKtakempis.com> wrote in message
news:#l**************@TK2MSFTNGP12.phx.gbl...
You must not be using Internet Explorer for your browser.

HTH,

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

"Anne" <li*******@yahoo.com> wrote in message
news:03****************************@phx.gbl...
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!


Nov 17 '05 #3

P: n/a
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" <li*******@yahoo.com> wrote in message
news:0f****************************@phx.gbl...
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!
-----Original Message-----
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?

"Kevin Spencer" <ke***@SPAMMERSSUCKtakempis.com> wrote in

message
news:#l**************@TK2MSFTNGP12.phx.gbl...
You must not be using Internet Explorer for your browser.
HTH,

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

"Anne" <li*******@yahoo.com> wrote in message
news:03****************************@phx.gbl...
> 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!
>

.

Nov 17 '05 #4

P: n/a

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 theserver side. It is on the client side, in the browser. The problem is thatyou can't send keys through the browser interface programmatically. It justisn't safe, and I don't expect that you ever will be able to. A hostile website 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 morecarefully). If this is a server-side event handler, you're barking way upthe wrong tree there. The good news is, you can get the effect you want onthe client side without a PostBack, and without having to use the clientkeyboard. While the TAB key moves the focus to the next form field in mostbrowsers, you can use the JavaScript focus() method to set the focus on anyform element you wish. So, what you really need is a client-side eventhandler that captures the ENTER key and sets the focus on the form elementyou desire. However, be advised that this is not standard browser behavior,and therefore may be contrary to the way that people expect their browser tobehave. 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 shiftthe 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" <li*******@yahoo.com> wrote in message
news:0f****************************@phx.gbl...
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!
>-----Original Message-----
>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?
>
>"Kevin Spencer" <ke***@SPAMMERSSUCKtakempis.com> wrote
in message
>news:#l**************@TK2MSFTNGP12.phx.gbl...
>> You must not be using Internet Explorer for your

browser.
>>
>> HTH,
>>
>> Kevin Spencer
>> Microsoft FrontPage MVP
>> Internet Developer
>> http://www.takempis.com
>> Some things just happen.
>> Everything else occurs.
>>
>> "Anne" <li*******@yahoo.com> wrote in message
>> news:03****************************@phx.gbl...
>> > 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!
>> >
>>
>>
>>
>
>
>.
>

.

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.