By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,309 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,309 IT Pros & Developers. It's quick & easy.

Response.Redirect not working when pressing the Enter key

P: n/a
Hi, I've been going crazy trying to figure out what's wrong with our
Asp.Net 2.0 intranet site.

At the very top of our main page I provide a TextBox and a Button for
submitting Google searches. Recently somebody pointed out to me that
you can't just press ENTER anymore after typing in the TextBox but
that you HAVE to click on the submit Button WITH THE MOUSE for it to
work. After some initial troubleshooting I discovered that it's only
an issue in IE 6 & 7 (works fine in FireFox!).

To simplify I created a brand new empty web form. I dropped an
<asp:TextBox/& <asp:Button/control on the the page (even made sure
they had the same ValidationGroup="google") and then wired up the
Button's click event.

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.google.com/search?q=" +
TextBox1.Text);
}

If you click the submit Button using the mouse the Response.Redirect
works fine. If you press ENTER on the keyboard while the focus is
still in the TextBox it does not work (the page just flashes/posts
back).

Let me clarify that the code in the Button1_Click event handler DOES
execute in both situations. Meaning if I put a breakpoint on the
Response.Redirect line and then run the debugger; when I type some
text into the TextBox and press ENTER on the keyboard the breakpoint
DOES get hit. When I step-out however, the page just refreshes and is
still sitting there. It's like the code is actually running ok and the
redirect is being sent to the client, but IE is then stopping it from
happening at the client-side somehow!? Alternatively, if I type into
the TextBox then do a SHIFT+TAB to put the focus on the submit button
itself, THEN pressing ENTER works.

How can I make it so that someone can type some text into a TextBox
and then just press ENTER on the keyboard? Anybody have any ideas?
Please?

Thanks in advance,
-Nick

Feb 14 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try using the DefaultButton attribute of the form tag. Here is an example
that I used for a login page I wrote:

<form id="form1" runat="server" defaultbutton="btnSubmit"
defaultfocus="txtUsername">

The DefaultButton is the ID of the Button you want "clicked" when the user
presses enter, and the DefaultFocus is the TextBox the the cursor is
initially in when the page first loads. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

<nk****@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hi, I've been going crazy trying to figure out what's wrong with our
Asp.Net 2.0 intranet site.

At the very top of our main page I provide a TextBox and a Button for
submitting Google searches. Recently somebody pointed out to me that
you can't just press ENTER anymore after typing in the TextBox but
that you HAVE to click on the submit Button WITH THE MOUSE for it to
work. After some initial troubleshooting I discovered that it's only
an issue in IE 6 & 7 (works fine in FireFox!).

To simplify I created a brand new empty web form. I dropped an
<asp:TextBox/& <asp:Button/control on the the page (even made sure
they had the same ValidationGroup="google") and then wired up the
Button's click event.

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.google.com/search?q=" +
TextBox1.Text);
}

If you click the submit Button using the mouse the Response.Redirect
works fine. If you press ENTER on the keyboard while the focus is
still in the TextBox it does not work (the page just flashes/posts
back).

Let me clarify that the code in the Button1_Click event handler DOES
execute in both situations. Meaning if I put a breakpoint on the
Response.Redirect line and then run the debugger; when I type some
text into the TextBox and press ENTER on the keyboard the breakpoint
DOES get hit. When I step-out however, the page just refreshes and is
still sitting there. It's like the code is actually running ok and the
redirect is being sent to the client, but IE is then stopping it from
happening at the client-side somehow!? Alternatively, if I type into
the TextBox then do a SHIFT+TAB to put the focus on the submit button
itself, THEN pressing ENTER works.

How can I make it so that someone can type some text into a TextBox
and then just press ENTER on the keyboard? Anybody have any ideas?
Please?

Thanks in advance,
-Nick

Feb 14 '07 #2

P: n/a
On Feb 13, 11:11 pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
Try using the DefaultButton attribute of the form tag. Here is an example
that I used for a login page I wrote:

<form id="form1" runat="server" defaultbutton="btnSubmit"
defaultfocus="txtUsername">

The DefaultButton is the ID of the Button you want "clicked" when the user
presses enter, and the DefaultFocus is the TextBox the the cursor is
initially in when the page first loads. Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

<nko...@gmail.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.com...
Hi, I've been going crazy trying to figure out what's wrong with our
Asp.Net 2.0 intranet site.
At the very top of our main page I provide a TextBox and a Button for
submitting Google searches. Recently somebody pointed out to me that
you can't just press ENTER anymore after typing in the TextBox but
that you HAVE to click on the submit Button WITH THE MOUSE for it to
work. After some initial troubleshooting I discovered that it's only
an issue in IE 6 & 7 (works fine in FireFox!).
To simplify I created a brand new empty web form. I dropped an
<asp:TextBox/& <asp:Button/control on the the page (even made sure
they had the same ValidationGroup="google") and then wired up the
Button's click event.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.google.com/search?q=" +
TextBox1.Text);
}
If you click the submit Button using the mouse theResponse.Redirect
works fine. If you press ENTER on the keyboard while the focus is
still in the TextBox it doesnotwork (the page just flashes/posts
back).
Let me clarify that the code in the Button1_Click event handler DOES
execute in both situations. Meaning if I put a breakpoint on the
Response.Redirectline and then run the debugger; when I type some
text into the TextBox and press ENTER on the keyboard the breakpoint
DOES get hit. When I step-out however, the page just refreshes and is
still sitting there. It's like the code is actually running ok and the
redirect is being sent to the client, but IE is then stopping it from
happening at the client-side somehow!? Alternatively, if I type into
the TextBox then do a SHIFT+TAB to put the focus on the submit button
itself, THEN pressing ENTER works.
How can I make it so that someone can type some text into a TextBox
and then just press ENTER on the keyboard? Anybody have any ideas?
Please?
Thanks in advance,
-Nick- Hide quoted text -

- Show quoted text -
Hey thanks for the help! Your suggestion led me down the right path to
fixing the problem, or at least patching it.

I tried to use the DefaultButton property on the Form tag but that
didn't work, oddly enough. I then tried wrapping the controls in a
Panel and set the Panel's DefaultButton and that seemed to get it
working in IE.

I am still left wondering what was going wrong... Before I even tried
to set the DefaultButton property it WAS submitting the Form and the
Button1_Click event WAS firing and the Response.Redirect() WAS being
executed on the server. When the WebResponse was recieved by IE it
seems like it just decided to ignore the redirect!? Why did it work
fine with FireFox and not in IE? I would like to understand exactly
what was going on behind the scenes. I hate not understanding why.

Feb 14 '07 #3

P: n/a
I understand how you feel, I usually like to understand the reasons for what
happens as well. I cannot say I know the answer to your question, but it
sounds to me like it might be partially browser related, since you are
mentioning both IE and FireFox. However, I do not have much experience when
it comes to the differences in the most popular browsers. It might also help
both me and other people trying to help you with this problem if you posted
your exact code. Although it is not very efficient, an alternative attemp to
solving your problem (although I have never tried it) would be to use the
JavaScript onKeyPress event to detect when the Enter key is pressed, and
execute the JavaScript form1.submit() method if event.keyCode (if using IE)
or event.which (for other browsers) is the keycode for the Enter key. Good
Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

<nk****@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
On Feb 13, 11:11 pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
>Try using the DefaultButton attribute of the form tag. Here is an example
that I used for a login page I wrote:

<form id="form1" runat="server" defaultbutton="btnSubmit"
defaultfocus="txtUsername">

The DefaultButton is the ID of the Button you want "clicked" when the
user
presses enter, and the DefaultFocus is the TextBox the the cursor is
initially in when the page first loads. Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

<nko...@gmail.comwrote in message

news:11**********************@m58g2000cwm.googleg roups.com...
Hi, I've been going crazy trying to figure out what's wrong with our
Asp.Net 2.0 intranet site.
At the very top of our main page I provide a TextBox and a Button for
submitting Google searches. Recently somebody pointed out to me that
you can't just press ENTER anymore after typing in the TextBox but
that you HAVE to click on the submit Button WITH THE MOUSE for it to
work. After some initial troubleshooting I discovered that it's only
an issue in IE 6 & 7 (works fine in FireFox!).
To simplify I created a brand new empty web form. I dropped an
<asp:TextBox/& <asp:Button/control on the the page (even made sure
they had the same ValidationGroup="google") and then wired up the
Button's click event.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.google.com/search?q=" +
TextBox1.Text);
}
If you click the submit Button using the mouse theResponse.Redirect
works fine. If you press ENTER on the keyboard while the focus is
still in the TextBox it doesnotwork (the page just flashes/posts
back).
Let me clarify that the code in the Button1_Click event handler DOES
execute in both situations. Meaning if I put a breakpoint on the
Response.Redirectline and then run the debugger; when I type some
text into the TextBox and press ENTER on the keyboard the breakpoint
DOES get hit. When I step-out however, the page just refreshes and is
still sitting there. It's like the code is actually running ok and the
redirect is being sent to the client, but IE is then stopping it from
happening at the client-side somehow!? Alternatively, if I type into
the TextBox then do a SHIFT+TAB to put the focus on the submit button
itself, THEN pressing ENTER works.
How can I make it so that someone can type some text into a TextBox
and then just press ENTER on the keyboard? Anybody have any ideas?
Please?
Thanks in advance,
-Nick- Hide quoted text -

- Show quoted text -

Hey thanks for the help! Your suggestion led me down the right path to
fixing the problem, or at least patching it.

I tried to use the DefaultButton property on the Form tag but that
didn't work, oddly enough. I then tried wrapping the controls in a
Panel and set the Panel's DefaultButton and that seemed to get it
working in IE.

I am still left wondering what was going wrong... Before I even tried
to set the DefaultButton property it WAS submitting the Form and the
Button1_Click event WAS firing and the Response.Redirect() WAS being
executed on the server. When the WebResponse was recieved by IE it
seems like it just decided to ignore the redirect!? Why did it work
fine with FireFox and not in IE? I would like to understand exactly
what was going on behind the scenes. I hate not understanding why.

Feb 15 '07 #4

P: n/a
On Feb 14, 12:56 pm, nko...@gmail.com wrote:
On Feb 13, 11:11 pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:


Try using the DefaultButton attribute of the form tag. Here is an example
that I used for a login page I wrote:
<form id="form1" runat="server" defaultbutton="btnSubmit"
defaultfocus="txtUsername">
The DefaultButton is the ID of the Button you want "clicked" when the user
presses enter, and the DefaultFocus is the TextBox the the cursor is
initially in when the page first loads. Good Luck!
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/
<nko...@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hi, I've been going crazy trying to figure out what's wrong with our
Asp.Net 2.0 intranet site.
At the very top of our main page I provide a TextBox and a Button for
submitting Google searches. Recently somebody pointed out to me that
you can't just press ENTER anymore after typing in the TextBox but
that you HAVE to click on the submit Button WITH THE MOUSE for it to
work. After some initial troubleshooting I discovered that it's only
an issue in IE 6 & 7 (works fine in FireFox!).
To simplify I created a brand new empty web form. I dropped an
<asp:TextBox/& <asp:Button/control on the the page (even made sure
they had the same ValidationGroup="google") and then wired up the
Button's click event.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.google.com/search?q=" +
TextBox1.Text);
}
If you click the submit Button using the mouse theResponse.Redirect
works fine. If you press ENTER on the keyboard while the focus is
still in the TextBox it doesnotwork (the page just flashes/posts
back).
Let me clarify that the code in the Button1_Click event handler DOES
execute in both situations. Meaning if I put a breakpoint on the
>Response.Redirectline and then run the debugger; when I type some
text into the TextBox and press ENTER on the keyboard the breakpoint
DOES get hit. When I step-out however, the page just refreshes and is
still sitting there. It's like the code is actually running ok and the
redirect is being sent to the client, but IE is then stopping it from
happening at the client-side somehow!? Alternatively, if I type into
the TextBox then do a SHIFT+TAB to put the focus on the submit button
itself, THEN pressing ENTER works.
How can I make it so that someone can type some text into a TextBox
and then just press ENTER on the keyboard? Anybody have any ideas?
Please?
Thanks in advance,
-Nick- Hide quoted text -
- Show quoted text -

Hey thanks for the help! Your suggestion led me down the right path to
fixing the problem, or at least patching it.

I tried to use the DefaultButton property on the Form tag but that
didn't work, oddly enough. I then tried wrapping the controls in a
Panel and set the Panel's DefaultButton and that seemed to get it
working in IE.

I am still left wondering what was going wrong... Before I even tried
to set the DefaultButton property it WAS submitting the Form and the
Button1_Click event WAS firing and the Response.Redirect() WAS being
executed on the server. When the WebResponse was recieved by IE it
seems like it just decided to ignore the redirect!? Why did it work
fine with FireFox and not in IE? I would like to understand exactly
what was going on behind the scenes. I hate not understanding why.- Hide quoted text -

- Show quoted text -
Can you please submit the code of how did you wrap the controls in a
panel. I have similar problem that with IE the response.redirect() is
not working but with Firefox it does.
- Sourik

Mar 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.