473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to prevent the enter key causing a form postback .net 1.1

Hi all

I've got a very complex form with loads of text boxes and buttons on it.
It's causing me all sorts of problems when users press the enter key and
cause a postback.

I need to disable the enter key. I've done some surfing and found some
Microsoft recommended code but it doesn't seem to work and I'm wondering what
I've done wrong. If possible I'd like to disable the enter key for the whole
form not for each text box (that would be sooooo complicated to implement).

I'm using .Net 1.1 and vb.

Here's what I've got at the moment.

<HEAD>
<title>Raise CSD</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<SCRIPT language="javascript">
function DisableKeyPress()
{
//alert(window.event.keyCode)
if (event.keyCode == 13)
{
event.cancelbubble = true;
event.returnvalue = false;
}
}
</SCRIPT>
</HEAD>
<body onKeyPress="DisableKeyPress()" vLink="#000000" aLink="#d9d5d2"
link="#d7451a" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server" >

then the code for the rest of the form.....

Thanks in advance!
Julia
Sep 17 '08 #1
5 2713
In the past, I did this with JavaScript, similar to what you have here.
Only, as I remember it, it wired up the Cancel event on body load and not
for each key press. I would google JavaScript enter key or even
event.keyCode == 13 for more suggestions.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
Hi all

I've got a very complex form with loads of text boxes and buttons on it.
It's causing me all sorts of problems when users press the enter key and
cause a postback.

I need to disable the enter key. I've done some surfing and found some
Microsoft recommended code but it doesn't seem to work and I'm wondering
what
I've done wrong. If possible I'd like to disable the enter key for the
whole
form not for each text box (that would be sooooo complicated to
implement).

I'm using .Net 1.1 and vb.

Here's what I've got at the moment.

<HEAD>
<title>Raise CSD</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<SCRIPT language="javascript">
function DisableKeyPress()
{
//alert(window.event.keyCode)
if (event.keyCode == 13)
{
event.cancelbubble = true;
event.returnvalue = false;
}
}
</SCRIPT>
</HEAD>
<body onKeyPress="DisableKeyPress()" vLink="#000000" aLink="#d9d5d2"
link="#d7451a" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server" >

then the code for the rest of the form.....

Thanks in advance!
Julia
Sep 17 '08 #2

Have found this and it works :-)

<Script language=javascript>
//this disables the enter key to stop form submission when the user
presses enter
document.onkeydown = doKey;

function doKey(E) {
if (event.keyCode==13)return false;
}
</script>

Thanks!
"Cowboy (Gregory A. Beamer)" wrote:
In the past, I did this with JavaScript, similar to what you have here.
Only, as I remember it, it wired up the Cancel event on body load and not
for each key press. I would google JavaScript enter key or even
event.keyCode == 13 for more suggestions.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
Hi all

I've got a very complex form with loads of text boxes and buttons on it.
It's causing me all sorts of problems when users press the enter key and
cause a postback.

I need to disable the enter key. I've done some surfing and found some
Microsoft recommended code but it doesn't seem to work and I'm wondering
what
I've done wrong. If possible I'd like to disable the enter key for the
whole
form not for each text box (that would be sooooo complicated to
implement).

I'm using .Net 1.1 and vb.

Here's what I've got at the moment.

<HEAD>
<title>Raise CSD</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<SCRIPT language="javascript">
function DisableKeyPress()
{
//alert(window.event.keyCode)
if (event.keyCode == 13)
{
event.cancelbubble = true;
event.returnvalue = false;
}
}
</SCRIPT>
</HEAD>
<body onKeyPress="DisableKeyPress()" vLink="#000000" aLink="#d9d5d2"
link="#d7451a" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server" >

then the code for the rest of the form.....

Thanks in advance!
Julia

Sep 17 '08 #3
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:55**********************************@microsof t.com...

[top-posting corrected]
>>I need to disable the Enter key.

In the past, I did this with JavaScript, similar to what you have here.
Only, as I remember it, it wired up the Cancel event on body load and not
for each key press. I would google JavaScript enter key or even
event.keyCode == 13 for more suggestions.

Have found this and it works :-)

<Script language=javascript>
The above script declaration has been deprecated for ages - use this
instead:

<script type="text/javascript">
if (event.keyCode==13)return false;
This is not cross-browser compatible - it will work only in IE:
http://www.google.co.uk/search?sourc...eyCode+firefox
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 17 '08 #4
Just be sure to test on other browsers, as some JavaScript only works with
some. Worst case is creating branches for different browsers.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:55**********************************@microsof t.com...
>
Have found this and it works :-)

<Script language=javascript>
//this disables the enter key to stop form submission when the user
presses enter
document.onkeydown = doKey;

function doKey(E) {
if (event.keyCode==13)return false;
}
</script>

Thanks!
"Cowboy (Gregory A. Beamer)" wrote:
>In the past, I did this with JavaScript, similar to what you have here.
Only, as I remember it, it wired up the Cancel event on body load and not
for each key press. I would google JavaScript enter key or even
event.keyCode == 13 for more suggestions.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:6F**********************************@microso ft.com...
Hi all

I've got a very complex form with loads of text boxes and buttons on
it.
It's causing me all sorts of problems when users press the enter key
and
cause a postback.

I need to disable the enter key. I've done some surfing and found some
Microsoft recommended code but it doesn't seem to work and I'm
wondering
what
I've done wrong. If possible I'd like to disable the enter key for the
whole
form not for each text box (that would be sooooo complicated to
implement).

I'm using .Net 1.1 and vb.

Here's what I've got at the moment.

<HEAD>
<title>Raise CSD</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<SCRIPT language="javascript">
function DisableKeyPress()
{
//alert(window.event.keyCode)
if (event.keyCode == 13)
{
event.cancelbubble = true;
event.returnvalue = false;
}
}
</SCRIPT>
</HEAD>
<body onKeyPress="DisableKeyPress()" vLink="#000000" aLink="#d9d5d2"
link="#d7451a" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server" >

then the code for the rest of the form.....

Thanks in advance!
Julia

Sep 17 '08 #5
This should be OK for me as it's for an intranet application and all users
will using IE.

Thanks for the warning anyway.

Julia

"Cowboy (Gregory A. Beamer)" wrote:
Just be sure to test on other browsers, as some JavaScript only works with
some. Worst case is creating branches for different browsers.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:55**********************************@microsof t.com...

Have found this and it works :-)

<Script language=javascript>
//this disables the enter key to stop form submission when the user
presses enter
document.onkeydown = doKey;

function doKey(E) {
if (event.keyCode==13)return false;
}
</script>

Thanks!
"Cowboy (Gregory A. Beamer)" wrote:
In the past, I did this with JavaScript, similar to what you have here.
Only, as I remember it, it wired up the Cancel event on body load and not
for each key press. I would google JavaScript enter key or even
event.keyCode == 13 for more suggestions.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
Hi all

I've got a very complex form with loads of text boxes and buttons on
it.
It's causing me all sorts of problems when users press the enter key
and
cause a postback.

I need to disable the enter key. I've done some surfing and found some
Microsoft recommended code but it doesn't seem to work and I'm
wondering
what
I've done wrong. If possible I'd like to disable the enter key for the
whole
form not for each text box (that would be sooooo complicated to
implement).

I'm using .Net 1.1 and vb.

Here's what I've got at the moment.

<HEAD>
<title>Raise CSD</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<SCRIPT language="javascript">
function DisableKeyPress()
{
//alert(window.event.keyCode)
if (event.keyCode == 13)
{
event.cancelbubble = true;
event.returnvalue = false;
}
}
</SCRIPT>
</HEAD>
<body onKeyPress="DisableKeyPress()" vLink="#000000" aLink="#d9d5d2"
link="#d7451a" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server" >

then the code for the rest of the form.....

Thanks in advance!
Julia


Sep 17 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gill Smith | last post by:
In my ASP.Net application when the user hit the enter key and the focus is on the edit box causing the page to postback. How to avoid this ? -Gish
5
by: Eric | last post by:
Hi All, I'm very experienced in traditional ASP and am new to (am learning) ASP.NET. FYI: I am initially learning ASP.NET with VB.NET to ease the transition for me. I have encountered what I...
0
by: Tony Hedge | last post by:
Hello, I can briefly explain without providing any code, it's a simple NET 1.1 web project. I have a web form with a textbox A and button A (in a table row), and textbox B and button B (in a...
6
by: Andrew Willett | last post by:
I have a web form that is a child of a Master Page. It is a login form for forms authentication. When you fill in the username and password box and press ENTER it doesnt process any of the...
4
by: peshrad | last post by:
Hi ! I'm working with Win 2K and Visual Studio 2003. I have a problem because pressing <ENTER> in a text input control causes a postback of my web form. Here comes some example code (already...
0
by: Vince Varallo | last post by:
Is there anyway to prevent a postback event when a web part is moved into a different zone? I am using the MSNBC weather web part and it fires a java script which is causing an error because the...
3
by: tanya | last post by:
I have a page with one form. I have one textbox in the page. I call a client-side function on the OnKeyUp event of the textbox. This function looks at the keycode of the keyup event on the textbox...
11
by: bill | last post by:
I dynamically create buttons and associate them with an event using AddHandler. I want all the button events to fire at one time, when the page is posted, instead of when each button is clicked....
0
by: josephkorn | last post by:
Hi all. I have a problem in my website in trying to prevent a user from double submitting the form. I am calling a subroutine from my page_load event that passes in the commandbutton that I want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.