keyDown

Discussion in 'ASP .Net' started by Anne, Jul 7, 2003.

  1. Anne

    Anne Guest

    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!
     
    Anne, Jul 7, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:035f01c3446a$61fc6960$...
    > 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!
    >
     
    Kevin Spencer, Jul 7, 2003
    #2
    1. Advertising

  3. Anne

    David Waz... Guest

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

    >
    >
    >
     
    David Waz..., Jul 8, 2003
    #3
  4. 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" <> wrote in message
    news:0f2601c344ea$fe62f500$...
    > 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" <> wrote in

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

    > >
    > >
    > >.
    > >
     
    Kevin Spencer, Jul 8, 2003
    #4
  5. Anne

    Anne Guest

    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" <> wrote in message
    >news:0f2601c344ea$fe62f500$...
    >> 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" <> wrote

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

    >
    >
    >.
    >
     
    Anne, Jul 9, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hb

    help: keyDown on textBox?

    hb, Mar 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,196
  2. George Durzi

    Capturing Enter KeyDown in a TextBox

    George Durzi, May 20, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    37,682
    George Durzi
    May 20, 2004
  3. mee-shell

    Keydown Event and Focus Problem

    mee-shell, Oct 23, 2004, in forum: Python
    Replies:
    0
    Views:
    577
    mee-shell
    Oct 23, 2004
  4. Claudia Fong

    keydown event

    Claudia Fong, Sep 17, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    1,964
    Claudia Fong
    Sep 18, 2007
  5. Replies:
    1
    Views:
    668
    cfps.Christian
    May 23, 2008
Loading...

Share This Page