enter-key works with two inputboxes but not with olny one.

P

Phil

Hi,

There is a form with two inputboxes and a submit button.The focus is on the
first inputbox.
When the user presses the enter-key without having entered some text, the
javascript message "wrong text" appears. This works.

But if i remove the second inputbox, leaving only the first inputbox and the
submit button, pressing the enter-key without any text does not show the
javascript message. Nothing happens. The focus remains in the inputbox. You
can see the page is postbacked, but that's all.

Why does it work with two inputboxes and not with one? And how to fix it?
Thanks
Phil


<body><form id="form1" runat="server">
<table>
<tr><td><input id="Text1" type="text" runat="server" /></td></tr>
<tr><td><input id="Text2" type="text" runat="server" /></td></tr>
<tr><td><input id="Submit1" type="submit" runat="server"
/></td></tr></table>
</form></body>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Text1.Focus()
End Sub

Protected Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Submit1.ServerClick
Dim beh As String
beh = Text1.value
If beh = "xxx" Then
Response.Redirect("start.aspx", False)
Else
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert('wrong text');", True)
End If
End Sub
 
C

Cubaman

Hi,

There is a form with two inputboxes and a submit button.The focus is on the
first inputbox.
When the user presses the enter-key without having entered some text, the
javascript message "wrong text" appears. This works.

But if i remove the second inputbox, leaving only the first inputbox and the
submit button, pressing the enter-key without any text does not show the
javascript message. Nothing happens. The focus remains in the inputbox. You
can see the page is postbacked, but that's all.

Why does it work with two inputboxes and not with one? And how to fix it?
Thanks
Phil

<body><form id="form1" runat="server">
<table>
 <tr><td><input id="Text1" type="text" runat="server" /></td></tr>
 <tr><td><input id="Text2" type="text"  runat="server" /></td></tr>
<tr><td><input id="Submit1" type="submit" runat="server"
/></td></tr></table>
</form></body>

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
 Text1.Focus()
 End Sub

Protected Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Submit1.ServerClick
        Dim beh As String
        beh = Text1.value
        If beh = "xxx" Then
             Response.Redirect("start.aspx", False)
        Else
            Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
            " alert('wrong text');", True)
        End If
End Sub

I think that you culd get better results using aspnet's validation
controls. You'll get validation on client side, among other benefits.
http://msdn.microsoft.com/en-us/library/aa479013.aspx
Best regards,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top