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

Javascript input.click() does not cause a Response.Redirect in asp.net

P: n/a
Hi all,

I have to use some javascript to "click" a search button on my aspx
page.

The server side btnSearch_Click executes prefectly, but there's a
Response.Redirect within the method, that does not get executed.

Any idea why it would execute all the code apart from the
Response.Redirect?

Kind regards,
Andre

Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Andre,

Does it get executed when you click the button with the mouse?

Eliyahu

<ah****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

I have to use some javascript to "click" a search button on my aspx
page.

The server side btnSearch_Click executes prefectly, but there's a
Response.Redirect within the method, that does not get executed.

Any idea why it would execute all the code apart from the
Response.Redirect?

Kind regards,
Andre

Nov 19 '05 #2

P: n/a
Not seen this behavior. As it triggers an internal excpetion perhaps
something with catching exceptions ? Seeing the minimal amount of code that
shows this behavior may help...

What if you just redirect without any other code ? If it stills doesn"t work
what if you just print out something to make sure the event handler is
called ?

--
Patrice

<ah****@gmail.com> a écrit dans le message de
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

I have to use some javascript to "click" a search button on my aspx
page.

The server side btnSearch_Click executes prefectly, but there's a
Response.Redirect within the method, that does not get executed.

Any idea why it would execute all the code apart from the
Response.Redirect?

Kind regards,
Andre

Nov 19 '05 #3

P: n/a
Hi Eliyahu,

Thanks for the swift reply.

Yeah it gets executed when you click on the button with the mouse, but
not when hitting the enter key.

(I'm pretty sure there's nothing wrong with the javascript. I'll post
my code below Partice's post)

Best,
Andre

Nov 19 '05 #4

P: n/a
Hi Patrice,

Thanks for the post.

I agree. It should work.

I'm pretty sure I'm missing something somewhere, but can't seem to find
it.

Here's the code as requested.

This is the javascript:
if(window.event.keyCode == 13)
{

var inputs = document.getElementsByTagName("input");

//I could've done a shorter version of this
//But we use a 3rd party cms (sitecore), which handles our layouts
//The cms causes webcontrol ID's to be rewritten to something
//like "uc_search0:btnSearch"
//So I have to search the id for the value "btnSearch"
for(var i = 0; i < inputs.length; i++)
{

if(inputs.item(i).id.toString().indexOf("btnSearch ") > -1)
{

inputs.item(i).click();
break;

}

}

}
//----------------------------------------------------------------------------------------------

And the server side code:
private void btnSearch_Click(object sender, System.EventArgs e)
{

string redirectURL = "http://www.google.com";

//...
//Some basic if statements, which might alter the URL according to
//the search criteria on the form
//...

Response.Redirect(redirectURL);

}
//----------------------------------------------------------------------------------------------

There's nothing funny in the Page_Load either.

I don't know if this behaviour might be caused by the cms. The cms uses
native aspx, so it shouldn't really be the culprit.

I'll do a quick test in plain aspx to see if it is in fact our cms.
Hope its not otherwise I've been wasting your time!

Best,
Andre

Nov 19 '05 #5

P: n/a
O yeah and the javascript is called on the body's "onkeydown" event.

Nov 19 '05 #6

P: n/a
Eh, I just did a test in plain aspx and it worked perfectly.

I'll have a fiddle with it for another while, and let you guys know how
it turned out.

Thanks,
Andre

Nov 19 '05 #7

P: n/a
your client code needs to cancel the event. the default behavior of a return
is a form submit, this will still happen, after your code does its own
submit.

-- bruce (sqlwork.com)
<ah****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi Patrice,

Thanks for the post.

I agree. It should work.

I'm pretty sure I'm missing something somewhere, but can't seem to find
it.

Here's the code as requested.

This is the javascript:
if(window.event.keyCode == 13)
{

var inputs = document.getElementsByTagName("input");

//I could've done a shorter version of this
//But we use a 3rd party cms (sitecore), which handles our layouts
//The cms causes webcontrol ID's to be rewritten to something
//like "uc_search0:btnSearch"
//So I have to search the id for the value "btnSearch"
for(var i = 0; i < inputs.length; i++)
{

if(inputs.item(i).id.toString().indexOf("btnSearch ") > -1)
{

inputs.item(i).click();
break;

}

}

}
//----------------------------------------------------------------------------------------------

And the server side code:
private void btnSearch_Click(object sender, System.EventArgs e)
{

string redirectURL = "http://www.google.com";

//...
//Some basic if statements, which might alter the URL according to
//the search criteria on the form
//...

Response.Redirect(redirectURL);

}
//----------------------------------------------------------------------------------------------

There's nothing funny in the Page_Load either.

I don't know if this behaviour might be caused by the cms. The cms uses
native aspx, so it shouldn't really be the culprit.

I'll do a quick test in plain aspx to see if it is in fact our cms.
Hope its not otherwise I've been wasting your time!

Best,
Andre

Nov 19 '05 #8

P: n/a
Hi Bruce,

Excellent! It works! Thanks for that.

For all those who want to know how to actually cancel the event, here
it is:

window.event.returnValue = false;

Many thanks,
Andre
Bruce Barker wrote:
your client code needs to cancel the event. the default behavior of a return
is a form submit, this will still happen, after your code does its own
submit.

-- bruce (sqlwork.com)
<ah****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi Patrice,

Thanks for the post.

I agree. It should work.

I'm pretty sure I'm missing something somewhere, but can't seem to find
it.

Here's the code as requested.

This is the javascript:
if(window.event.keyCode == 13)
{

var inputs = document.getElementsByTagName("input");

//I could've done a shorter version of this
//But we use a 3rd party cms (sitecore), which handles our layouts
//The cms causes webcontrol ID's to be rewritten to something
//like "uc_search0:btnSearch"
//So I have to search the id for the value "btnSearch"
for(var i = 0; i < inputs.length; i++)
{

if(inputs.item(i).id.toString().indexOf("btnSearch ") > -1)
{

inputs.item(i).click();
break;

}

}

}
//----------------------------------------------------------------------------------------------

And the server side code:
private void btnSearch_Click(object sender, System.EventArgs e)
{

string redirectURL = "http://www.google.com";

//...
//Some basic if statements, which might alter the URL according to
//the search criteria on the form
//...

Response.Redirect(redirectURL);

}
//----------------------------------------------------------------------------------------------

There's nothing funny in the Page_Load either.

I don't know if this behaviour might be caused by the cms. The cms uses
native aspx, so it shouldn't really be the culprit.

I'll do a quick test in plain aspx to see if it is in fact our cms.
Hope its not otherwise I've been wasting your time!

Best,
Andre


Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.