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?

1
  • If you're posting back from an UpdatePanel, use the ScriptManager instead of ClientScript. Check for their parameter ordering also Commented Nov 3, 2015 at 16:15

4 Answers 4

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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'

Comments

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'

Comments

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.