469,903 Members | 1,998 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Javascript location.href not working

Here is my code created when a page loads the first time:

string jScript =
@"

<script
language='javaScript'>
var pop = false;
function
CancelPage()
{
var ans =
false;
ans =
confirm('Are you sure you want to Cancel and lose any
changes?');
if (ans)
{

alert('yes');

parent.location.href = 'OrderMisc.aspx';
}
}
</script>";

if ( !IsStartupScriptRegistered
("CancelPage") )
RegisterStartupScript
("CancelPage", jScript);

btnCancel.Attributes.Add
("onclick","javascript: pop=true;CancelPage();");
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++

Code is called correctly when the Cancel button is
pressed because I get the confirmation box, I click yes
and I get the alert box from the code, then the page
reloads without redirecting to 'OrderMaint.aspx'.

OrderMaint.aspx is spelled correctly and in the same
directory so I'm not sure why it's not taking me there.

Any ideas?

Thanks,
Darin
Nov 18 '05 #1
1 2239
Hi,

If button is asp.net server control or HTML submit button you need to
cancel it default behavior by cancel event bubbling and returning false
from your javascript function:

window.event.returnValue = false;
window.event.cancelBubble = true;
Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.