Stopping auto submit...

G

Guest

This one has me perplexed

from vs.net web app

add a new aspx pag
add 3 textbox's and a command butto
in the command buttons click event add response.write "button1 click

from any textbox press the enter ke
the Button1 Click event fire

add a new button, do nothing else except add respnse.write "buttonX click
it's click event might fire but it might be button1.. no real differences to the buttons properties but for some reason (that I can identify)

If anything I would prefer the Enter key to act as a tab key, the only cure I have found is to make the textbox a multiLine textbox. However, I would prefer not to do this, but I can't have someone submitting the form before all the textbox's have entrys (yes I know about fieldvalidators, I would just prefer not to have the it happen and or to have the page do something else

Thanks

Ro
 
V

vMike

Add this event to your text boxes onkeydown="javascript:testForEnter()"

add add this to your page.

<SCRIPT LANGUAGE="javascript">
function testForEnter()
{
if (event.keyCode == 13)
{
event.cancelBubble = true;
event.returnValue = false;
}
}
</SCRIPT>

Rob Lynch said:
This one has me perplexed.

from vs.net web app.

add a new aspx page
add 3 textbox's and a command button
in the command buttons click event add response.write "button1 click"

from any textbox press the enter key
the Button1 Click event fires

add a new button, do nothing else except add respnse.write "buttonX click"
it's click event might fire but it might be button1.. no real differences
to the buttons properties but for some reason (that I can identify)
If anything I would prefer the Enter key to act as a tab key, the only
cure I have found is to make the textbox a multiLine textbox. However, I
would prefer not to do this, but I can't have someone submitting the form
before all the textbox's have entrys (yes I know about fieldvalidators, I
would just prefer not to have the it happen and or to have the page do
something else.
 
G

Guest

Ken

It sure sounds like exactly the same behavour that I have been seeing. It seems like the solution being proposed requires the use of fieldvalidators... There are a couple of fileds that are OK if they are blank, but I still don't want the enter to do the autosubmit

I am going with a combo of what vMike suggests (was doing something ike that and a programatic autotab - for the textbox's that are singleline..

Of course just squeltching the enter via event.returnvalue = false or multiline would be ok, I have decided I will also go the extra 1inch and add an auto tab

Thanks for the effort. I think you found the problem I was seeing

Ro

PS Was my other address a good one?
 
G

Guest

What I ended up with (and it seems to work quite well) - Thanks All

Code Behind Pag

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'Put user code to initialize the page her
TextBox1.Attributes.Add("onkeypress", "setEnterKey('TextBox1');"
TextBox2.Attributes.Add("onkeypress", "setEnterKey('TextBox2');"
End Su

Web Pag

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MailTo.aspx.vb" Inherits="XXXXXXX.MailTo"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><script language="JavaScript"><!-

function setEnterKey(btnName)
if (event.keyCode == 13)
event.cancelBubble = true

if (btnName=="TextBox1")
eval('this.Form1.TextBox2.focus()')

else if (btnName == "TextBox2")
eval('this.Form1.Button1.focus()')

event.returnValue = false

}
//--></script></HEAD><body><form id="Form1" method="post" runat="server"><asp:TextBox id="TextBox1" runat="server"></asp:TextBox><asp:TextBox id="TextBox2" runat="server"></asp:TextBox><asp:Button id="Button1" runat="server" Text="Button"></asp:Button></form></body></HTML>
 
K

Ken Cox [Microsoft MVP]

Hi Rob,
PS Was my other address a good one?

Sorry, no idea. MVPs don't have anything to do with Microsoft's MSDN Managed
Support service except that some of us are also signed up for it as
customers.

Ken
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top