Pressing <ENTER> in text input control causes a postback !

P

peshrad

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 stripped of most of the unnecessary
code):

----------------------------------------------------------------------------
----------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7PmA5uGMyk9VLm/FRbF5zeYsdMA+5" />

<INPUT onkeydown="alert('Hi, down !');" onkeyup="alert('Hi, up!');">
</form>
</body>
</HTML>
----------------------------------------------------------------------------
----------------------------------------------------------

The postback occurs after the onkeydown event and before the onkeyup event,
but I don't understand why.

Does anybody know a way of avoiding this undesirable automatic postback ?

Your kind help would be appreciated.

Peter
 
G

Grant Merwitz

take the action of the form:
action="WebForm1.aspx"
This is whats causing the form to submit.

But why are you doing this onkeydown/onkeyup.
It is highly annoying, and my page got stuck after i fixed it, as everytime
i tried to leave the textbox it caused the key up popup, then when i closed
the popup it causd the key down popup.

Anyway, HTH
 
P

peshrad

take the action of the form:
action="WebForm1.aspx"
This is whats causing the form to submit.

How can I suppress the "action" argument in the <form> tag of an ASPX page ?
The "action" argument was set by IIS automatically. I hadn't specified any
value for it.
The code in my first posting was code sent by IIS to the browser.
The original ASPX file's content was the following:

----------------------------------------------------------------------------
---------------------------------------------------
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TestEnter.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT onkeydown="alert('Hi, down !');" onkeyup="alert('Hi, up!');">
</form>
</body>
</HTML>
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top