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.webcontro ls
> Path: cpmsftngxa06.phx.gbl
> Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontro ls:15504
> NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
>
> 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
>
>