Hit enter and have btn_click event fire?

Discussion in 'ASP .Net Web Controls' started by m miller, Dec 31, 2003.

  1. m miller

    m miller Guest

    I'm stumped. I have two apps. both with an HTML INPUT text field and an
    asp:button.

    In one app when I enter text and hit the enter button on the keyboard, the
    asp:button click event fires,
    in the other app it doesn't fire. Both buttons have the same attributes and
    both input fields have
    identical attributes. CausesValidation=false, EnabledViewState=true.

    I cannot, for the life of me, figure out the difference. I've even
    inspected the <body> and <form> tags, smartnavigation, etc.
    All aspects seem to be the same.


    TIA,
    M. Miller
    m miller, Dec 31, 2003
    #1
    1. Advertising

  2. Hi

    Based on my understanding, you have 2 web form application(Asp.net
    application), almost the same, when click button(enter button), one
    application fires click event, while the other did not fire.

    I think your problem is somewhat strange, both your button click events
    should fire.
    Are your buttons server side button controls?(with attribute runat=server).
    Only server side control will fire the server side event.
    For your second application, when you click enter button, does the
    page_load event fire?(You can determine this through set breakpoint in you
    Page_Load event)

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 2, 2004
    #2
    1. Advertising

  3. m miller

    Deepthroat Guest

    I can confirm this behaviour.

    Create a simple webform with a server side TextEdit
    control and a server side Button control with an OnClick
    handler.

    Run the app, click on the TextEdit control and press the
    Enter button. The page OnLoad handler as expected, but the
    button's OnClick handler will not.

    However, if you then add a second TextEdit control to the
    page, the OnClick will execute! But if you then hide the
    second TextEdit control, it will not be rendered on the
    WebPage and then the OnClick will not execute.

    If you use an HTML Input control (not server side) instead
    as the second text edit control then it will work again.
    But if use a hidden HTML Input control (type=hidden) it
    stops working again.

    However if you add the HTML Input control and give it
    style="VISIBILITY: hidden" then it will work!

    This behaviour is present in both VS2002 and VS2003.

    I do not have a satisfactory explanation about this
    behaviour. I can only find some obscure jscript work
    around hacks on the net. This issue has been around since
    day one and I can't believe that an MCP claims ignorance
    about this now.

    This issue alone has delayed the rollout of one my ASP.Net
    apps for over a month and has cost us a lot of time and
    money.

    This is a general comment, But I yet to complete a 12
    month project in 3 months. Does anyone actually believe
    this "do more with less" nonsense? I apologize for my
    cynicism, but I have yet to meet anyone who can honestly
    claim that ASP.NET has made them more productive. In fact,
    I've never missed so many deadlines since I've started
    using it because of issues like this.

    Regards,

    Deepthroat

    >-----Original Message-----
    >
    >Hi
    >
    >Based on my understanding, you have 2 web form application

    (Asp.net
    >application), almost the same, when click button(enter

    button), one
    >application fires click event, while the other did not

    fire.
    >
    >I think your problem is somewhat strange, both your

    button click events
    >should fire.
    >Are your buttons server side button controls?(with

    attribute runat=server).
    >Only server side control will fire the server side event.
    >For your second application, when you click enter button,

    does the
    >page_load event fire?(You can determine this through set

    breakpoint in you
    >Page_Load event)
    >
    >Best regards,
    >Jeffrey Tan
    >Microsoft Online Partner Support
    >Get Secure! - www.microsoft.com/security
    >This posting is provided "as is" with no warranties and

    confers no rights.
    >
    >.
    >
    Deepthroat, Jan 2, 2004
    #3
  4. Hi Deepthroat and mmiller,

    Thanks for Deepthroat's confirm, I think I have misunderstand mmiler. I now
    see the "enter button"'s meanning.(It is the "enter button" of the keyboard)
    I have reproduced out your problem.
    I think you can work around this through register a hidden field for your
    button:
    private void Page_Load(object sender, System.EventArgs e)
    {
    Page.RegisterHiddenField("__EVENTTARGET", "Button1");
    }
    Note: relplace "Button1" with your button's name

    Hope this helps,

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 2, 2004
    #4
  5. m miller

    m miller Guest

    Thank you both for taking time to answer my question. I used Deepthroat's
    solution, because it was the simplest, but both solutions work.
    I spent about 24 hours trying to solve this on my own and never would have
    come close to the answer. The app. that the functionality did work
    in, indeed did have a second input object, but who would have thought that
    would have been the solution.

    Arrrrrrrrrrrrrghh!

    Regards,
    m miller






    "Deepthroat" <> wrote in message
    news:03bb01c3d0eb$0b0b0770$...
    > I can confirm this behaviour.
    >
    > Create a simple webform with a server side TextEdit
    > control and a server side Button control with an OnClick
    > handler.
    >
    > Run the app, click on the TextEdit control and press the
    > Enter button. The page OnLoad handler as expected, but the
    > button's OnClick handler will not.
    >
    > However, if you then add a second TextEdit control to the
    > page, the OnClick will execute! But if you then hide the
    > second TextEdit control, it will not be rendered on the
    > WebPage and then the OnClick will not execute.
    >
    > If you use an HTML Input control (not server side) instead
    > as the second text edit control then it will work again.
    > But if use a hidden HTML Input control (type=hidden) it
    > stops working again.
    >
    > However if you add the HTML Input control and give it
    > style="VISIBILITY: hidden" then it will work!
    >
    > This behaviour is present in both VS2002 and VS2003.
    >
    > I do not have a satisfactory explanation about this
    > behaviour. I can only find some obscure jscript work
    > around hacks on the net. This issue has been around since
    > day one and I can't believe that an MCP claims ignorance
    > about this now.
    >
    > This issue alone has delayed the rollout of one my ASP.Net
    > apps for over a month and has cost us a lot of time and
    > money.
    >
    > This is a general comment, But I yet to complete a 12
    > month project in 3 months. Does anyone actually believe
    > this "do more with less" nonsense? I apologize for my
    > cynicism, but I have yet to meet anyone who can honestly
    > claim that ASP.NET has made them more productive. In fact,
    > I've never missed so many deadlines since I've started
    > using it because of issues like this.
    >
    > Regards,
    >
    > Deepthroat
    >
    > >-----Original Message-----
    > >
    > >Hi
    > >
    > >Based on my understanding, you have 2 web form application

    > (Asp.net
    > >application), almost the same, when click button(enter

    > button), one
    > >application fires click event, while the other did not

    > fire.
    > >
    > >I think your problem is somewhat strange, both your

    > button click events
    > >should fire.
    > >Are your buttons server side button controls?(with

    > attribute runat=server).
    > >Only server side control will fire the server side event.
    > >For your second application, when you click enter button,

    > does the
    > >page_load event fire?(You can determine this through set

    > breakpoint in you
    > >Page_Load event)
    > >
    > >Best regards,
    > >Jeffrey Tan
    > >Microsoft Online Partner Support
    > >Get Secure! - www.microsoft.com/security
    > >This posting is provided "as is" with no warranties and

    > confers no rights.
    > >
    > >.
    > >
    m miller, Jan 2, 2004
    #5
  6. Hi mmiller,

    Oh, I also want to point out that this "strange" behavior of not firing the
    button click event when there is only one textbox is related to IE, not
    ASP.NET or any other server-side component.

    When IE contains a page with a form that contains two or more text boxes,
    when you hit enter while a text box has focus, it will submit the form and
    include the name of the first submit button on the form in the request
    data. However, if there is only one text box, it will submit the form
    without including any submit button data.

    This can be confirmed with a simple ASP page. It can also be verified by
    monitoring the network packets sent from the browser to the server.

    The following ASP page demonstrates this issue:
    <html>
    <head>
    <% response.Write(request.Form("Submit1")) %>
    </head>
    <body>
    <form action="" method="post">
    <INPUT id="Text1" type="text" name="Text1">
    <INPUT id="Submit1" type="submit" value="Submit" name="Submit1">
    </form>
    </body>
    </html>

    If you set focus on the text box and hit enter, the form is submitted, but
    the Response.Write does not write anything because the request data did not
    include data about the submit button. If you add another text box and try
    again, the Response.Write will display "Submit".

    This is because, with two text boxes, the browser includes "Submit1=Submit"
    as part of the form data sent to the server. With only one text box, the
    browser does not include this data.

    Hope this makes sense to you.
    Have a nice day!

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 6, 2004
    #6
    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. Veeresh
    Replies:
    1
    Views:
    1,196
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2004
  2. Chad Gerber
    Replies:
    0
    Views:
    464
    Chad Gerber
    Mar 15, 2006
  3. CK
    Replies:
    9
    Views:
    384
    Jerry Rasmussen
    Oct 19, 2006
  4. Brad Smith
    Replies:
    0
    Views:
    168
    Brad Smith
    Apr 7, 2004
  5. HopfZ
    Replies:
    0
    Views:
    542
    HopfZ
    Aug 28, 2006
Loading...

Share This Page