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

Discussion in 'ASP .Net' started by peshrad, Aug 26, 2005.

  1. peshrad

    peshrad Guest

    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
     
    peshrad, Aug 26, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%...
    > 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
    >
    >
     
    Grant Merwitz, Aug 26, 2005
    #2
    1. Advertising

  3. peshrad

    peshrad Guest

    > 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>
    ----------------------------------------------------------------------------
    ---------------------------------------------------
     
    peshrad, Aug 26, 2005
    #3
  4. thats wierd, doesn't post back for me.

    Try attached


    "peshrad" <> wrote in message
    news:...
    >> 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>
    > ----------------------------------------------------------------------------
    > ---------------------------------------------------
    >
    >
    >
    >
    >
     
    Grant Merwitz, Aug 26, 2005
    #4
  5. Hi,

    This behaviour is by design if form contains just one input. See
    http://ppewww.ph.gla.ac.uk/~flavell/www/formquestion.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
    >
    >
    >
     
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=, Aug 26, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry
    Replies:
    4
    Views:
    1,199
    John Saunders
    Jul 25, 2003
  2. Cindy
    Replies:
    2
    Views:
    11,423
    Charlie Nilsson [MSFT]
    Mar 3, 2004
  3. paul
    Replies:
    1
    Views:
    535
    Jonathan Mcdougall
    Aug 4, 2003
  4. LaBird

    Input without pressing enter?

    LaBird, Oct 16, 2003, in forum: C Programming
    Replies:
    6
    Views:
    1,217
    Joona I Palaste
    Oct 16, 2003
  5. HopfZ
    Replies:
    0
    Views:
    631
    HopfZ
    Aug 28, 2006
Loading...

Share This Page