Hit enter and have btn_click event fire?

M

m miller

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
 
J

Jeffrey Tan[MSFT]

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

Deepthroat

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
 
J

Jeffrey Tan[MSFT]

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

m miller

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
 
J

Jeffrey Tan[MSFT]

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.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top