For Mike regarding ENTER from the text box

Discussion in 'ASP .Net Web Controls' started by JP, Oct 21, 2003.

  1. JP

    JP Guest

    Hi Mike,

    Thank You! I think this will get me what I am trying to
    do. However, for the first attempt, it didn't work. I am
    sorry, but I am still a new fish in the ocean of ASP.NET
    and it would help if you could give more details on how to
    use the code you gave.

    This is what I did....
    In the page load event I added the KeyDown event, but
    changed the syntax to proper cases. Following is the exact
    line I entered.
    txtPassword.Attributes.Add("OnKeyDown", "return
    TestForEnter()")

    Now is a little confusing part for me, to add the script
    in HTML codes. I added this <script></script> right after
    <head></head>, not sure if that's okay!

    <script>
    function testForEnter() {
    if (event.keyCode == 13)
    {
    document.all("imgLogin").click();
    event.returnValue = false;
    }
    }
    </script>

    Now I run the app and for the password first character,
    which is an upper case letter, I press SHIFT key and the
    page's bottom left corner shows the yellow triangle
    indicating an error. And the error is ...

    Line: 80
    Char: 1
    Error: Object Expected
    Code: 0
    URL: http://localhost/NAVAlertData/Login.aspx

    Line 80 on my HTML page is a </TR> ending tag and line 80
    on my Login.aspx.vb (code behind) is commented out. So now
    I don't know what to look for...

    Please help....

    Thanks a million again in advance!
    JP

    >-----Original Message-----
    >Hi JP,
    >
    >This is normal behavior and there is a workaround. When

    there are text
    >boxes and buttons on a form, pressing enter while in a

    text box will
    >activate the first of the buttons in the sequence they

    are defined in the
    >HTML.
    >
    >One solution is to place your preferred button first in

    the HTML and use
    >grid layout to display it where ever you want.
    >
    >Another solution is to capture the enter key in the text

    box and redirect
    >its behavior. Here's a sample for doing this.
    >
    >First, we need to add the keydown event to each text box.

    You can do this
    >in the code behind as follows:
    > Private Sub Page_Load(ByVal sender As System.Object,

    ByVal e As
    >System.EventArgs) Handles MyBase.Load
    > TextBox1.Attributes.Add("onkeydown", "return

    testForEnter()")
    > TextBox2.Attributes.Add("onkeydown", "return

    testForEnter()")
    > End Sub
    >
    >Next, we need client-side javascript to process the key

    down. Here is a
    >sample which causes the third image button to click

    rather than the first.
    >
    ><script>
    >function testForEnter() {
    > if (event.keyCode == 13)
    > {
    > document.all("ImageButton3").click();
    > event.returnValue = false;
    > }
    >}
    ></script>
    >
    >Setting the returnValue to false prevents the first

    button from also firing.
    >
    >Does this answer your question?
    >
    >Thank you, Mike
    >Microsoft, ASP.NET Support Professional
    >
    >Microsoft highly recommends to all of our customers that

    they visit the
    >http://www.microsoft.com/protect site and perform the

    three straightforward
    >steps listed to improve your computer's security.
    >
    >This posting is provided "AS IS", with no warranties, and

    confers no rights.
    >
    >
    >--------------------
    >> Content-Class: urn:content-classes:message
    >> From: "JP" <>
    >> Sender: "JP" <>
    >> Subject: Accept ENTER Key from the TextBox
    >> Date: Mon, 20 Oct 2003 09:33:54 -0700
    >> Lines: 19
    >> Message-ID: <07e101c39727$f3fba5a0$>
    >> MIME-Version: 1.0
    >> Content-Type: text/plain;
    >> charset="iso-8859-1"
    >> Content-Transfer-Encoding: 7bit
    >> X-Newsreader: Microsoft CDO for Windows 2000
    >> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    >> Thread-Index: AcOXJ/P7qdmv8j4QTFyAwzwhzA63PQ==
    >> Newsgroups:

    microsoft.public.dotnet.framework.aspnet.webcontrols
    >> Path: cpmsftngxa06.phx.gbl
    >> Xref: cpmsftngxa06.phx.gbl

    >microsoft.public.dotnet.framework.aspnet.webcontrols:15504
    >> NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
    >> X-Tomcat-NG:

    microsoft.public.dotnet.framework.aspnet.webcontrols
    >>
    >> Hi,
    >>
    >> I have a login screen and have usual stuff on it
    >> including "Forgot Password" and "Change Password" as

    image
    >> buttons along with "Login" as image button.
    >>
    >> Now, when I enter Id/Password and hit ENTER, it's

    accepted
    >> by the "Forgot Password" image button and not

    by "Login".
    >> I threw my "Login" codes into "txtPassword_TextChanged"
    >> event and it worked, but still sometimes it goes
    >> to "Forgot Password".
    >>
    >> Any help to make "Login" accept the ENTER Key
    >> from "Password" text box will be much appreciated.
    >>
    >> Thanks a million!
    >> Regards,
    >> JP
    >>
    >>

    >
    >.
    >
     
    JP, Oct 21, 2003
    #1
    1. Advertising

  2. Hi JP,

    It's your capitalization. You changed attributes.add to TestForEnter.
    However, you left the function as testForEnter. The initial "t" is
    capitalized in one but not the other. As a side note, we usually put event
    driven script inside the head section, though it will work just about
    anywhere.

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > Content-Class: urn:content-classes:message
    > From: "JP" <>
    > Sender: "JP" <>
    > Subject: For Mike regarding ENTER from the text box
    > Date: Tue, 21 Oct 2003 06:14:57 -0700
    > Lines: 163
    > Message-ID: <0a5e01c397d5$532110d0$>
    > MIME-Version: 1.0
    > Content-Type: text/plain;
    > charset="iso-8859-1"
    > Content-Transfer-Encoding: 7bit
    > X-Newsreader: Microsoft CDO for Windows 2000
    > X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > Thread-Index: AcOX1VMhlf3eksZUQaCD7JS04XMLjw==
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > Path: cpmsftngxa06.phx.gbl
    > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:15528
    > NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    > Hi Mike,
    >
    > Thank You! I think this will get me what I am trying to
    > do. However, for the first attempt, it didn't work. I am
    > sorry, but I am still a new fish in the ocean of ASP.NET
    > and it would help if you could give more details on how to
    > use the code you gave.
    >
    > This is what I did....
    > In the page load event I added the KeyDown event, but
    > changed the syntax to proper cases. Following is the exact
    > line I entered.
    > txtPassword.Attributes.Add("OnKeyDown", "return
    > TestForEnter()")
    >
    > Now is a little confusing part for me, to add the script
    > in HTML codes. I added this <script></script> right after
    > <head></head>, not sure if that's okay!
    >
    > <script>
    > function testForEnter() {
    > if (event.keyCode == 13)
    > {
    > document.all("imgLogin").click();
    > event.returnValue = false;
    > }
    > }
    > </script>
    >
    > Now I run the app and for the password first character,
    > which is an upper case letter, I press SHIFT key and the
    > page's bottom left corner shows the yellow triangle
    > indicating an error. And the error is ...
    >
    > Line: 80
    > Char: 1
    > Error: Object Expected
    > Code: 0
    > URL: http://localhost/NAVAlertData/Login.aspx
    >
    > Line 80 on my HTML page is a </TR> ending tag and line 80
    > on my Login.aspx.vb (code behind) is commented out. So now
    > I don't know what to look for...
    >
    > Please help....
    >
    > Thanks a million again in advance!
    > JP
    >
    > >-----Original Message-----
    > >Hi JP,
    > >
    > >This is normal behavior and there is a workaround. When

    > there are text
    > >boxes and buttons on a form, pressing enter while in a

    > text box will
    > >activate the first of the buttons in the sequence they

    > are defined in the
    > >HTML.
    > >
    > >One solution is to place your preferred button first in

    > the HTML and use
    > >grid layout to display it where ever you want.
    > >
    > >Another solution is to capture the enter key in the text

    > box and redirect
    > >its behavior. Here's a sample for doing this.
    > >
    > >First, we need to add the keydown event to each text box.

    > You can do this
    > >in the code behind as follows:
    > > Private Sub Page_Load(ByVal sender As System.Object,

    > ByVal e As
    > >System.EventArgs) Handles MyBase.Load
    > > TextBox1.Attributes.Add("onkeydown", "return

    > testForEnter()")
    > > TextBox2.Attributes.Add("onkeydown", "return

    > testForEnter()")
    > > End Sub
    > >
    > >Next, we need client-side javascript to process the key

    > down. Here is a
    > >sample which causes the third image button to click

    > rather than the first.
    > >
    > ><script>
    > >function testForEnter() {
    > > if (event.keyCode == 13)
    > > {
    > > document.all("ImageButton3").click();
    > > event.returnValue = false;
    > > }
    > >}
    > ></script>
    > >
    > >Setting the returnValue to false prevents the first

    > button from also firing.
    > >
    > >Does this answer your question?
    > >
    > >Thank you, Mike
    > >Microsoft, ASP.NET Support Professional
    > >
    > >Microsoft highly recommends to all of our customers that

    > they visit the
    > >http://www.microsoft.com/protect site and perform the

    > three straightforward
    > >steps listed to improve your computer's security.
    > >
    > >This posting is provided "AS IS", with no warranties, and

    > confers no rights.
    > >
    > >
    > >--------------------
    > >> Content-Class: urn:content-classes:message
    > >> From: "JP" <>
    > >> Sender: "JP" <>
    > >> Subject: Accept ENTER Key from the TextBox
    > >> Date: Mon, 20 Oct 2003 09:33:54 -0700
    > >> Lines: 19
    > >> Message-ID: <07e101c39727$f3fba5a0$>
    > >> MIME-Version: 1.0
    > >> Content-Type: text/plain;
    > >> charset="iso-8859-1"
    > >> Content-Transfer-Encoding: 7bit
    > >> X-Newsreader: Microsoft CDO for Windows 2000
    > >> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > >> Thread-Index: AcOXJ/P7qdmv8j4QTFyAwzwhzA63PQ==
    > >> Newsgroups:

    > microsoft.public.dotnet.framework.aspnet.webcontrols
    > >> Path: cpmsftngxa06.phx.gbl
    > >> Xref: cpmsftngxa06.phx.gbl

    > >microsoft.public.dotnet.framework.aspnet.webcontrols:15504
    > >> NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
    > >> X-Tomcat-NG:

    > microsoft.public.dotnet.framework.aspnet.webcontrols
    > >>
    > >> Hi,
    > >>
    > >> I have a login screen and have usual stuff on it
    > >> including "Forgot Password" and "Change Password" as

    > image
    > >> buttons along with "Login" as image button.
    > >>
    > >> Now, when I enter Id/Password and hit ENTER, it's

    > accepted
    > >> by the "Forgot Password" image button and not

    > by "Login".
    > >> I threw my "Login" codes into "txtPassword_TextChanged"
    > >> event and it worked, but still sometimes it goes
    > >> to "Forgot Password".
    > >>
    > >> Any help to make "Login" accept the ENTER Key
    > >> from "Password" text box will be much appreciated.
    > >>
    > >> Thanks a million!
    > >> Regards,
    > >> JP
    > >>
    > >>

    > >
    > >.
    > >

    >
     
    Mike Moore [MSFT], Oct 21, 2003
    #2
    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. fe

    To Mike Treseler only

    fe, Mar 5, 2004, in forum: VHDL
    Replies:
    2
    Views:
    578
    Duane Clark
    Mar 6, 2004
  2. Jim Demetri

    Mike Taylor?

    Jim Demetri, Nov 27, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    408
  3. Gnarlodious
    Replies:
    4
    Views:
    17,610
    elizas
    May 5, 2010
  4. Bigmac Turdsplash

    if string = "mike" then print "Hi mike"

    Bigmac Turdsplash, May 6, 2009, in forum: Ruby
    Replies:
    4
    Views:
    177
    Heesob Park
    May 6, 2009
  5. HopfZ
    Replies:
    0
    Views:
    576
    HopfZ
    Aug 28, 2006
Loading...

Share This Page