Highlited default key does not work. Can any one explain this ?

G

Guest

Thanks for taking the time to read this note

Can anyone explain what went wrong and any ideas how to fix it

I have a search page With three buttons few drop downs and a textbox. The search Button is the default button (because it is the first control in the HTML

When anything is entered into the text box the button is highlighted automatically. Hitting the enter key the event handler for this button btnSearch_click is executed. This worked fine for a few times and then something changed. Now it does not work

Here's what happens. When the button is highlighted by default (when a textpox gets focus and anything is entered)
hitting enter key nothing happens. I set break points and it does execute page load event so it posts the form back but does not execute the event btnSearch_click

When button is set to focus by tabbing to it (highlited by a dashed box) and hit the enter key, the event btnsearch_click executes

When the button is clicked with the mouse the event btnSearch_click executes
 
B

bruce barker

its a bug in IE. there are cases when hitting enter (depending on the mix of
controls), that it fail to post the button name, thus the o click does not
fire.

in your post back code, you can check if none of the buttons are in the
posted form data, then fire the click event your self.

if (this.IsPostBack)
{
bool buttonClicked = false;
foreach(string key in this.Request.Form.Keys)
{
if (string.Compare(key,"button1",true) == 0
&& (string.Compare(key,"button2",true) == 0
&& (string.Compare(key,"button3",true) == 0)
buttonClicked = true;
}

if (buttonClicked)
// do click i want
}



-- bruce (sqlwork.com)


makthar said:
Thanks for taking the time to read this note.

Can anyone explain what went wrong and any ideas how to fix it.

I have a search page With three buttons few drop downs and a textbox. The
search Button is the default button (because it is the first control in the
HTML)
When anything is entered into the text box the button is highlighted
automatically. Hitting the enter key the event handler for this button
btnSearch_click is executed. This worked fine for a few times and then
something changed. Now it does not work.
Here's what happens. When the button is highlighted by default (when a
textpox gets focus and anything is entered)
hitting enter key nothing happens. I set break points and it does execute
page load event so it posts the form back but does not execute the event
btnSearch_click.
When button is set to focus by tabbing to it (highlited by a dashed box)
and hit the enter key, the event btnsearch_click executes.
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top