Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Hit enter and have btn_click event fire?

Reply
Thread Tools

Hit enter and have btn_click event fire?

 
 
m miller
Guest
Posts: n/a
 
      12-31-2003
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


 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-02-2004

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.

 
Reply With Quote
 
 
 
 
Deepthroat
Guest
Posts: n/a
 
      01-02-2004
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.
>
>.
>

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-02-2004

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.

 
Reply With Quote
 
m miller
Guest
Posts: n/a
 
      01-02-2004
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" <(E-Mail Removed)> wrote in message
news:03bb01c3d0eb$0b0b0770$(E-Mail Removed)...
> 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.
> >
> >.
> >



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      01-06-2004

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.

 
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
Can't hit the site by name but I can hit by IP CK ASP .Net 9 10-19-2006 08:01 PM
capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue. HopfZ Javascript 0 08-28-2006 10:11 AM
Btn_Click event does not fire when used in a MasterPage Chad Gerber ASP .Net 0 03-15-2006 01:48 AM
Triggering Button clicked event when I hit enter key at edit box.... Veeresh ASP .Net 1 06-16-2004 07:38 AM
asp:button : refresh parent and close child at end of btn_click Brad Smith ASP .Net Web Controls 0 04-07-2004 03:07 PM



Advertisments