Javascript location.href not working

D

Darin Browne

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
 
N

Natty Gur

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
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top