keyDown

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anne

    #1

    keyDown

    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_Ke yDown(ByVal sender As
    System.Object, ByVal e As
    System.Windows. Forms.KeyEventA rgs) Handles
    txtRequestor.Ke yDown
    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

    #2
    Re: keyDown

    You must not be using Internet Explorer for your browser.

    HTH,

    Kevin Spencer
    Microsoft FrontPage MVP
    Internet Developer
    All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

    Some things just happen.
    Everything else occurs.

    "Anne" <lilanne_2@yaho o.com> wrote in message
    news:035f01c344 6a$61fc6960$a00 1280a@phx.gbl.. .[color=blue]
    > 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_Ke yDown(ByVal sender As
    > System.Object, ByVal e As
    > System.Windows. Forms.KeyEventA rgs) Handles
    > txtRequestor.Ke yDown
    > 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!
    >[/color]


    Comment

    • David Waz...

      #3
      Re: keyDown

      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" <kevin@SPAMMERS SUCKtakempis.co m> wrote in message
      news:#lo8$QIRDH A.1564@TK2MSFTN GP12.phx.gbl...[color=blue]
      > 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" <lilanne_2@yaho o.com> wrote in message
      > news:035f01c344 6a$61fc6960$a00 1280a@phx.gbl.. .[color=green]
      > > 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_Ke yDown(ByVal sender As
      > > System.Object, ByVal e As
      > > System.Windows. Forms.KeyEventA rgs) Handles
      > > txtRequestor.Ke yDown
      > > 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!
      > >[/color]
      >
      >
      >[/color]


      Comment

      • Kevin Spencer

        #4
        Re: keyDown

        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 programmaticall y. 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.fo cus();
        }
        // --></script>

        "elementNam e" 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="GetE nter()">

        HTH,

        Kevin Spencer
        Microsoft FrontPage MVP
        Internet Developer
        All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

        Some things just happen.
        Everything else occurs.

        "Anne" <lilanne_2@yaho o.com> wrote in message
        news:0f2601c344 ea$fe62f500$a00 1280a@phx.gbl.. .[color=blue]
        > 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!
        >[color=green]
        > >-----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[/color]
        > puzzling. Is this a WEB[color=green]
        > >project (that's what this N.G. is for) or is this a desk-[/color]
        > top application?[color=green]
        > >
        > >"Kevin Spencer" <kevin@SPAMMERS SUCKtakempis.co m> wrote in[/color]
        > message[color=green]
        > >news:#lo8$QIRD HA.1564@TK2MSFT NGP12.phx.gbl.. .[color=darkred]
        > >> You must not be using Internet Explorer for your[/color][/color]
        > browser.[color=green][color=darkred]
        > >>
        > >> HTH,
        > >>
        > >> Kevin Spencer
        > >> Microsoft FrontPage MVP
        > >> Internet Developer
        > >> http://www.takempis.com
        > >> Some things just happen.
        > >> Everything else occurs.
        > >>
        > >> "Anne" <lilanne_2@yaho o.com> wrote in message
        > >> news:035f01c344 6a$61fc6960$a00 1280a@phx.gbl.. .
        > >> > hie again, i have 3 textbox and i would like the user[/color][/color]
        > to[color=green][color=darkred]
        > >> > go to the next textbox by pressing the 'ENTER' key. i[/color][/color]
        > have[color=green][color=darkred]
        > >> > tried using this:
        > >> >
        > >> > Private Sub txtRequestor_Ke yDown(ByVal sender As
        > >> > System.Object, ByVal e As
        > >> > System.Windows. Forms.KeyEventA rgs) Handles
        > >> > txtRequestor.Ke yDown
        > >> > 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[/color][/color]
        > other[color=green][color=darkred]
        > >> > reference (i have already added System.Windows. Forms)[/color][/color]
        > so[color=green][color=darkred]
        > >> > that the keyDown event can be found? or is there[/color][/color]
        > another[color=green][color=darkred]
        > >> > way to do this?
        > >> >
        > >> > Thanx!
        > >> >
        > >>
        > >>
        > >>[/color]
        > >
        > >
        > >.
        > >[/color][/color]


        Comment

        • Anne

          #5
          Re: keyDown


          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!
          [color=blue]
          >-----Original Message-----
          >Hi Anne,
          >
          >Yes, there is an onkeydown event for a text box. However,[/color]
          it is not on the[color=blue]
          >server side. It is on the client side, in the browser.[/color]
          The problem is that[color=blue]
          >you can't send keys through the browser interface[/color]
          programmaticall y. It just[color=blue]
          >isn't safe, and I don't expect that you ever will be able[/color]
          to. A hostile web[color=blue]
          >site could type any combination of keys on a client[/color]
          computer if that was so.[color=blue]
          >
          >I mistakenly thought that you had written a client-side[/color]
          event handler there,[color=blue]
          >as it looks a lot like one for Internet Explorer (should[/color]
          have looked more[color=blue]
          >carefully). If this is a server-side event handler,[/color]
          you're barking way up[color=blue]
          >the wrong tree there. The good news is, you can get the[/color]
          effect you want on[color=blue]
          >the client side without a PostBack, and without having to[/color]
          use the client[color=blue]
          >keyboard. While the TAB key moves the focus to the next[/color]
          form field in most[color=blue]
          >browsers, you can use the JavaScript focus() method to[/color]
          set the focus on any[color=blue]
          >form element you wish. So, what you really need is a[/color]
          client-side event[color=blue]
          >handler that captures the ENTER key and sets the focus on[/color]
          the form element[color=blue]
          >you desire. However, be advised that this is not standard[/color]
          browser behavior,[color=blue]
          >and therefore may be contrary to the way that people[/color]
          expect their browser to[color=blue]
          >behave. Here is an example:
          >
          ><script type="text/javascript"><!--
          >function GetEnter()
          >{
          > if (event.keyCode == 13) document.forms[/color]
          [0].elementName.fo cus();[color=blue]
          >}
          >// --></script>
          >
          >"elementName " is the name attribute of the form element[/color]
          you want to shift[color=blue]
          >the focus to.
          >
          >In Your textbox, just add an "onkeydown" event handler.[/color]
          Example:[color=blue]
          >
          ><input type="text" name="myText" size="20"[/color]
          onkeydown="GetE nter()">[color=blue]
          >
          >HTH,
          >
          >Kevin Spencer
          >Microsoft FrontPage MVP
          >Internet Developer
          >http://www.takempis.com
          >Some things just happen.
          >Everything else occurs.
          >
          >"Anne" <lilanne_2@yaho o.com> wrote in message
          >news:0f2601c34 4ea$fe62f500$a0 01280a@phx.gbl. ..[color=green]
          >> hie david, yes, this is a web project. but i am trying 2
          >> integrate that keyDown event from the[/color][/color]
          system.windows. forms.[color=blue][color=green]
          >> are u sure there's no such thing for a textbox in[/color][/color]
          asp.net?[color=blue][color=green]
          >> anybody else have any idea on how i can use similar
          >> function as the keyDown?
          >>
          >> thanx 4 all the help!
          >>[color=darkred]
          >> >-----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[/color]
          >> puzzling. Is this a WEB[color=darkred]
          >> >project (that's what this N.G. is for) or is this a[/color][/color][/color]
          desk-[color=blue][color=green]
          >> top application?[color=darkred]
          >> >
          >> >"Kevin Spencer" <kevin@SPAMMERS SUCKtakempis.co m> wrote[/color][/color][/color]
          in[color=blue][color=green]
          >> message[color=darkred]
          >> >news:#lo8$QIRD HA.1564@TK2MSFT NGP12.phx.gbl.. .
          >> >> You must not be using Internet Explorer for your[/color]
          >> browser.[color=darkred]
          >> >>
          >> >> HTH,
          >> >>
          >> >> Kevin Spencer
          >> >> Microsoft FrontPage MVP
          >> >> Internet Developer
          >> >> http://www.takempis.com
          >> >> Some things just happen.
          >> >> Everything else occurs.
          >> >>
          >> >> "Anne" <lilanne_2@yaho o.com> wrote in message
          >> >> news:035f01c344 6a$61fc6960$a00 1280a@phx.gbl.. .
          >> >> > hie again, i have 3 textbox and i would like the[/color][/color][/color]
          user[color=blue][color=green]
          >> to[color=darkred]
          >> >> > go to the next textbox by pressing the 'ENTER'[/color][/color][/color]
          key. i[color=blue][color=green]
          >> have[color=darkred]
          >> >> > tried using this:
          >> >> >
          >> >> > Private Sub txtRequestor_Ke yDown(ByVal sender As
          >> >> > System.Object, ByVal e As
          >> >> > System.Windows. Forms.KeyEventA rgs) Handles
          >> >> > txtRequestor.Ke yDown
          >> >> > 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[/color][/color][/color]
          in[color=blue][color=green]
          >> other[color=darkred]
          >> >> > reference (i have already added[/color][/color][/color]
          System.Windows. Forms)[color=blue][color=green]
          >> so[color=darkred]
          >> >> > that the keyDown event can be found? or is there[/color]
          >> another[color=darkred]
          >> >> > way to do this?
          >> >> >
          >> >> > Thanx!
          >> >> >
          >> >>
          >> >>
          >> >>
          >> >
          >> >
          >> >.
          >> >[/color][/color]
          >
          >
          >.
          >[/color]

          Comment

          Working...