6

In html file to redirect a page using Javascript i used like this

window.location.href = "http://www.google.com/";

Its working fine. But when i tried in .aspx it is not working Below is my code. Thanks in advance

<head runat="server">
<script type="text/javascript">
   function PageRedirect() {
       window.location.href = "http://www.google.com/";
   }
 </script>
</head>
<body>
<form runat="server">
  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="PageRedirect()"/>
  </form>
2
  • Its working is IE for me , but not in chrome. Commented Mar 6, 2013 at 11:11
  • Its not working for me in IE and Chrome but below change is working fine Commented Mar 6, 2013 at 11:18

1 Answer 1

8

Try this:

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="PageRedirect(); return false;"/>
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you working fine i want to know in detail can you send any reference link that useful for me
Try this too: <asp:Button ID="Button1" Text="Button" OnClientClick="PageRedirect();"/> (not sure). link: w3schools.com/aspnet/prop_webcontrol_button_onclientclick.asp
When i kept return false its working fine otherwise not. Want to know why to mention return
return false prevents default action. default action in this case is postback to the server, which is prevented
Yes in the function also we can return false

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.