473,320 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

javascript redirect in asp.net?

I've got a Web page written in C#, and when it runs and the user presses
enter, it submits the first button on the form. As you'd expect. I want
the system to redirect to a different page when a user pressed enter from a
second textbox. I've used the line of code in the Page_Load:

SearchString.Attributes.Add("onKeyDown", "if (window.event) if
(window.event.keyCode == 13)
window.location='searchresults.asp?SearchString=' +
document.Form1.QuickSearch_SearchString.value;");

Problem is: it doesn't damn work. If I put an alert('test'); in the
beginning, it fires. However, it never actually gets past the conditions,
even though I've used (and tested!) this script on classic ASP pages; it
just submits the first button. I've tried changing it to onKeyPress, but
still no luck.

Has anyone successfully got this working, or can someone see something I'm
doing stupid here?

Thanks in advance,

Duncan
Nov 17 '05 #1
3 11767
Did you try setting window.event.cancelBubble = true? This will prevent the
enter event on the textbox to be bubbled up the the higher event handler.

- Shuvro

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
I've got a Web page written in C#, and when it runs and the user presses
enter, it submits the first button on the form. As you'd expect. I want
the system to redirect to a different page when a user pressed enter from a second textbox. I've used the line of code in the Page_Load:

SearchString.Attributes.Add("onKeyDown", "if (window.event) if
(window.event.keyCode == 13)
window.location='searchresults.asp?SearchString=' +
document.Form1.QuickSearch_SearchString.value;");

Problem is: it doesn't damn work. If I put an alert('test'); in the
beginning, it fires. However, it never actually gets past the conditions,
even though I've used (and tested!) this script on classic ASP pages; it
just submits the first button. I've tried changing it to onKeyPress, but
still no luck.

Has anyone successfully got this working, or can someone see something I'm
doing stupid here?

Thanks in advance,

Duncan

Nov 17 '05 #2
I added that to my script:

SearchString.Attributes.Add("onKeyDown", "if (window.event) if
(window.event.keyCode == 13) {
window.location='venuesearchresults.asp?SearchStri ng=' +
document.Form1.QuickSearch_SearchString.value; window.event.cancelBubble =
true; } ");

....but still no banana.

Any other thoughts? Or have I gone around that the wrong way?

Duncan

"Shuvro Mazumder [MSFT]" <sh*****@online.microsoft.com> wrote in message
news:eT*************@TK2MSFTNGP15.phx.gbl...
Did you try setting window.event.cancelBubble = true? This will prevent the enter event on the textbox to be bubbled up the the higher event handler.

- Shuvro

--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
I've got a Web page written in C#, and when it runs and the user presses
enter, it submits the first button on the form. As you'd expect. I want the system to redirect to a different page when a user pressed enter from
a
second textbox. I've used the line of code in the Page_Load:

SearchString.Attributes.Add("onKeyDown", "if (window.event) if
(window.event.keyCode == 13)
window.location='searchresults.asp?SearchString=' +
document.Form1.QuickSearch_SearchString.value;");

Problem is: it doesn't damn work. If I put an alert('test'); in the
beginning, it fires. However, it never actually gets past the

conditions, even though I've used (and tested!) this script on classic ASP pages; it
just submits the first button. I've tried changing it to onKeyPress, but still no luck.

Has anyone successfully got this working, or can someone see something I'm doing stupid here?

Thanks in advance,

Duncan


Nov 17 '05 #3
I think that the Form Submit on the ENTER key being pressed raises another
event other than the "OnKeyDown" which actually fires the form. You have to
write a handler for that event and set the cancelBubble=true;

Look up the list of events supported on a <INPUT type=Text> element. You
might want to try the onkeypress event.

- Shuvro
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
I added that to my script:

SearchString.Attributes.Add("onKeyDown", "if (window.event) if
(window.event.keyCode == 13) {
window.location='venuesearchresults.asp?SearchStri ng=' +
document.Form1.QuickSearch_SearchString.value; window.event.cancelBubble =
true; } ");

...but still no banana.

Any other thoughts? Or have I gone around that the wrong way?

Duncan

"Shuvro Mazumder [MSFT]" <sh*****@online.microsoft.com> wrote in message
news:eT*************@TK2MSFTNGP15.phx.gbl...
Did you try setting window.event.cancelBubble = true? This will prevent

the
enter event on the textbox to be bubbled up the the higher event handler.

- Shuvro

--
This posting is provided "AS IS" with no warranties, and confers no

rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
I've got a Web page written in C#, and when it runs and the user presses enter, it submits the first button on the form. As you'd expect. I

want the system to redirect to a different page when a user pressed enter from
a
second textbox. I've used the line of code in the Page_Load:

SearchString.Attributes.Add("onKeyDown", "if (window.event) if
(window.event.keyCode == 13)
window.location='searchresults.asp?SearchString=' +
document.Form1.QuickSearch_SearchString.value;");

Problem is: it doesn't damn work. If I put an alert('test'); in the
beginning, it fires. However, it never actually gets past the

conditions, even though I've used (and tested!) this script on classic ASP pages; it just submits the first button. I've tried changing it to onKeyPress, but still no luck.

Has anyone successfully got this working, or can someone see something I'm doing stupid here?

Thanks in advance,

Duncan



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ryann | last post by:
I hate javascript looking for help. I am trying to pass hidden fields around without showing a query string in the address bar. e.g. formA.asp not formA.asp?var1=blah&var2=blah I have...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
9
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET...
3
by: Shapper | last post by:
Hello, I am working on an ASP.NET/VB web site. I have several links including menu links. Considerer a want to load a page named page.aspx. I can do it using javascript. Or using this code:...
3
by: TJ | last post by:
Hi, I would like to ask something to user after user submits the form... I know I can ask user whehter they want to submit the form or not using client-script code such as onClick or onSubmit by...
2
by: SteveSu | last post by:
Hi! I want to make a postback when the user hits the escape-button on the keyboard and redirect the user to another page. But the response.redirect does not work for me in this "context". I´m...
8
by: Taras_96 | last post by:
Hi everyone, We' ve come to the conclusion that we wish the user to be directed to an error page if javascript is disabled <enter comment about how a webpage shouldn't rely on javascript here :)...
1
by: rkagrawal | last post by:
I am not sure if this is the right forum to post about this problem , but , i just want to discuss a problem i recently encountered. I was developing a page in ASP , where i came across a problem....
2
by: Seth Williams | last post by:
In the middle of my event handler (for a button), I have an if/then statement (using vb.net): if (whatever) then strScript="<script ....... strScript &= alert('This is an alert') strscript...
2
by: Rahina | last post by:
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html This is a free website I am doing for some friends, so nothing fancy. And, I learned web...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.