Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Pressing <ENTER> in text input control causes a postback !

Reply
Thread Tools

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

 
 
peshrad
Guest
Posts: n/a
 
      08-26-2005
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


 
Reply With Quote
 
 
 
 
Grant Merwitz
Guest
Posts: n/a
 
      08-26-2005
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

"peshrad" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
peshrad
Guest
Posts: n/a
 
      08-26-2005
> 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>
----------------------------------------------------------------------------
---------------------------------------------------





 
Reply With Quote
 
Grant Merwitz
Guest
Posts: n/a
 
      08-26-2005
thats wierd, doesn't post back for me.

Try attached


"peshrad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> 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>
> ----------------------------------------------------------------------------
> ---------------------------------------------------
>
>
>
>
>





 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
Guest
Posts: n/a
 
      08-26-2005
Hi,

This behaviour is by design if form contains just one input. See
http://ppewww.ph.gla.ac.uk/~flavell/...mquestion.html
for more information.

Milosz Skalecki
MCP, MCAD

"peshrad" wrote:

> 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
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileUpload causes error when pressing the browser back button.. ScottyinLA ASP .Net Web Controls 0 04-07-2006 11:49 PM
Postback caused by pressing the "enter" key Cindy ASP .Net 2 03-03-2004 11:02 PM
Postback causes 100=Continue, causes double download prompt? Xavier Osa ASP .Net 0 01-09-2004 11:17 AM
Input without pressing Enter paul C++ 1 08-04-2003 02:59 PM
input=text fires Submit when pressing Enter Jerry ASP .Net 4 07-25-2003 01:38 PM



Advertisments