problem with redirecting page with OnClientClick

D

Dan

Hi,

i try to redirect to another aspx page with jscript. I use "OnClientClick"
but nothing happens.
I tried two ways.
What am i doing wrong?
Thanks
Dan

....
<form id="form1" runat="server">
<asp:Button ID="ContinueButton" runat="server" OnClientClick="return
profiel()" />
</form>
....

<script language="javascript" type="text/javascript">
function profiel()
{
//window.location.href="page2.aspx"
Response.Redirect("page2.aspx")
}
</script>
 
G

Guest

Yes, the problem is that you are trying to use Response.Redirect (which is
server-side .NET code) in client-side script, which won't work. Use
location.href=newurl;

instead.
Peter
 
G

Guest

P.S.
Also, you need to return false after the window.location.href assignment to
prevent your server-side event from firing; then it will work.
Peter
 
D

Dan

thanks

Peter Bromberg said:
P.S.
Also, you need to return false after the window.location.href assignment
to
prevent your server-side event from firing; then it will work.
Peter
 
G

Guest

Yes, the problem is that you are trying to use Response.Redirect (which is
server-side .NET code) in client-side script, which won't work. Use
location.href=newurl;

instead.
Peter

I'd recommend to move js above and add "return false"

Example:


<script language="javascript" type="text/javascript">
function profiel()
{
window.location.href="page2.aspx";
return false;

}
</script>

<asp:Button ID="ContinueButton" runat="server" OnClientClick="return
profiel();" />
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top