event mechanism behaves in unexpected way.

Discussion in 'ASP .Net' started by Francois Malgreve, Nov 19, 2003.

  1. Hi all,

    I have a more or less complex form with a few buttons and a few input
    fields.
    One of my my input field ( a TextBox) I have an event handler for the
    TextChanged event.
    What I want is that when I will hit enter in my input field, I expect to
    form to be posted back to the server and the event handler for the
    TextChanged event to be called.
    If i tabulate from my text field, everythign is working fine. Nevertheless
    when I hit the <enter> key instead of tabulating, then not only event
    handler for that field is called but also the event handler of the first
    button of my form. Why does this event fires? Is it because when I hit
    <enter> the browser, translate it as if I clicked on that button? Or is it
    due to some event mechanism in ASP.NET? Could anyone who understand what
    really happen under the bush could explain it to me? And maybe give me a
    hint on how to accomplish the desired behaviour.

    Thanks in advance.

    Here is some excerpts of my code:

    ASPX page:
    .....
    <asp:textbox id="TextBoxInputAccountId" style="Z-INDEX: 150; LEFT: 312px;
    POSITION: absolute; TOP: 8px" runat="server" Width="80px"
    AutoPostBack="True">
    .....



    Code behind class:
    In the InitializeComponent() called from the OnInit() method I have the
    registration of my event handler for my event:
    .....
    this.TextBoxInputAccountId.TextChanged += new
    System.EventHandler(this.LoadAccountDetail);
    .....


    Generated HTML code for IE browser:

    <script language="javascript">
    <!--
    function __doPostBack(eventTarget, eventArgument) {
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
    theform = document.forms["FormMemberDetails"];
    }
    else {
    theform = document.FormMemberDetails;
    }
    theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
    }
    // -->
    </script>

    .....
    <input name="TextBoxInputAccountId" type="text"
    onchange="__doPostBack('TextBoxInputAccountId','')" language="javascript"
    id="TextBoxInputAccountId" />
    .....
    Francois Malgreve, Nov 19, 2003
    #1
    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. Do
    Replies:
    1
    Views:
    336
    Natty Gur
    Nov 16, 2003
  2. RJN
    Replies:
    1
    Views:
    674
    Curt_C [MVP]
    Sep 24, 2004
  3. DeltaOne
    Replies:
    31
    Views:
    865
    S.Tobias
    May 20, 2005
  4. Steven Woody

    Event Handling and Signal-Slot Mechanism

    Steven Woody, Jan 19, 2009, in forum: Python
    Replies:
    2
    Views:
    1,059
    Steven Woody
    Jan 20, 2009
  5. Greg Hauptmann
    Replies:
    7
    Views:
    154
    Mark Thomas
    Nov 10, 2008
Loading...

Share This Page