473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

problem with redirecting page with OnClientClick

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>
Feb 12 '07 #1
5 18461
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Dan" wrote:
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>
Feb 12 '07 #2
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Dan" wrote:
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>
Feb 12 '07 #3
On Feb 12, 5:48 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Dan" wrote:
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>- Hide quoted text -
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();" />

Feb 12 '07 #4
Dan
thanks

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comschreef in
bericht news:10**********************************@microsof t.com...
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Dan" wrote:
>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>

Feb 12 '07 #5
On Feb 12, 6:03 pm, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
>
I'd recommend to move js above and add "return false"
Well, Peter mentioned it already :-)

Feb 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lozd | last post by:
Would appreciate any solutions people could offer for this. Basically I wan't to use a frameset with an aspx page as the contents rather than a htm page and I'd like to be able to redirect the...
3
by: Paul | last post by:
Hi all, at present I I've built a website which can be updated by admin and users. My problem, I've combined "log in" and "access levels" to restrict access to certain pages, using the built...
11
by: ElmoWatson | last post by:
I tried on the Security newgroup, as well as other places, and haven't gotten an answer yet - - I'm pulling my hair out over this one. I'm trying to get Forms Authentication working.....I can get...
1
by: Ankur Jain | last post by:
Hi, I am facing a very weird problem while redirecting to another page. The problem is as follows: I have a website. I build the solution and run the application. The first page is the login...
0
by: jtencate | last post by:
I am trying to add an OnClientClick event to links in an asp:Menu. I tried using a StaticItemTemplate to bind the MenuItem data to a LinkButton with an OnClientClick attribute. This works fine to...
3
by: Jeff | last post by:
I'm hoping that someone can help me. I know little javascript and only need a very small amount in a visual web 2005 application using vb. I'm not sure whether my problem is related to the java or...
5
by: Slim | last post by:
i have a simple page, with one button button1. when click it creates a new button button 2 and adds a event handler to it. but when button 2 is clicked nothing happens, why? Partial Class...
0
by: veerapureddy | last post by:
Hi All, I have some problem with browser caching I cleared the cache and also invalidated the session and redirected to the login page if the session has expired, in IE there is no problem if I go...
0
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.