Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > keyDown

Reply
Thread Tools

keyDown

 
 
Anne
Guest
Posts: n/a
 
      07-07-2003
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!

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      07-07-2003
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" <(E-Mail Removed)> wrote in message
news:035f01c3446a$61fc6960$(E-Mail Removed)...
> 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!
>



 
Reply With Quote
 
 
 
 
David Waz...
Guest
Posts: n/a
 
      07-08-2003
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" <(E-Mail Removed)> wrote in message
news:#lo8$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:035f01c3446a$61fc6960$(E-Mail Removed)...
> > 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!
> >

>
>
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      07-08-2003
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" <(E-Mail Removed)> wrote in message
news:0f2601c344ea$fe62f500$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in

> message
> >news:#lo8$(E-Mail Removed)...
> >> 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" <(E-Mail Removed)> wrote in message
> >> news:035f01c3446a$61fc6960$(E-Mail Removed)...
> >> > 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!
> >> >
> >>
> >>
> >>

> >
> >
> >.
> >



 
Reply With Quote
 
Anne
Guest
Posts: n/a
 
      07-09-2003

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" <(E-Mail Removed)> wrote in message
>news:0f2601c344ea$fe62f500$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote

in
>> message
>> >news:#lo8$(E-Mail Removed)...
>> >> 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" <(E-Mail Removed)> wrote in message
>> >> news:035f01c3446a$61fc6960$(E-Mail Removed)...
>> >> > 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!
>> >> >
>> >>
>> >>
>> >>
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keydown event problem when enter key is pressed Gouri.Mahajan7@gmail.com ASP .Net 1 05-23-2008 12:20 PM
keydown event Claudia Fong ASP .Net 5 09-18-2007 08:52 AM
Keydown Event and Focus Problem mee-shell Python 0 10-23-2004 01:07 AM
Capturing Enter KeyDown in a TextBox George Durzi ASP .Net 4 05-20-2004 06:49 PM
help: keyDown on textBox? hb ASP .Net 2 03-05-2004 06:02 PM



Advertisments