1

Hi ladies and gentlemen,

I am trying to call the alert from the button, and after the alert I want it to redirect to my home page. However when I call the below code from asp button

ClientScript.RegisterStartupScript(this.GetType(), "Success", "alert('" + "Activation mail has been sent to the email address. Please check your email!" + "');window.location.href('Home.aspx');", true);

It doesn't work. The alert can be call so this javascript is correct. What I suspect is the postback cause the redirect doesn't work. So I put the update panel as the result the button cannot be call the function at all.

In the end I tried to put return false in the javascript also not working.

I also tried to put response redirect after call the javascript function but the javascript and the behind code running synchronize so the page will be redirect before the alert will call.

How I can achieve my scenario?

Ryan Shine
  • 442
  • 1
  • 9
  • 23
  • If you're posting back from an UpdatePanel, use the ScriptManager instead of ClientScript. Check for their parameter ordering also – haraman Nov 03 '15 at 16:15

4 Answers4

1

try this.

ClientScript.RegisterStartupScript(this.GetType(), "Success", "alert('Activation mail has been sent to the email address. Please check your email!');window.location ='Home.aspx';", true);
Jigneshk
  • 350
  • 1
  • 7
  • Welcome to Stack Overflow! While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – ryanyuyu Nov 03 '15 at 20:57
0

href is not a function, so you cannot call it like href('Home.aspx'). Change

window.location.href('Home.aspx')

to

window.location ='Home.aspx'
Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
0

As the other answers say:

 window.location.href = 'Home.aspx'

However that is a relative path, so it only works if the current page is in the same folder as the Home page. Redirecting to a relative URL in JavaScript.

Use '/' to go to the root folder of your website:

 window.location.href = '/Home.aspx'
Community
  • 1
  • 1
0

I suggest you instead of using

window.location.href('')

Use

window.location.replace('')

if you want to redirect like an html redirect.
Source: How to redirect to another webpage in JavaScript/jQuery?

However, like says you can use :

window.location ='Home.aspx'

Community
  • 1
  • 1
Charly
  • 7
  • 5