![]() |
![]() OCAU News - Wiki - QuickLinks - Pix - Sponsors |
|
|||||||
| Notices |
|
Sign up for a free OCAU account and this ad will go away! Search our forums with Google: |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Member
Join Date: Jun 2001
Location: Sydney
Posts: 4,202
|
I want to create an ASP page with a button that will redirect me to another page.
My problem is that "Response.Redirect()" seems to be a server-side object and can't be called from a client-side script/subroutine. The result being, I cant use onClick= to call a redirect. I've tried several different things, my latest effort being below Code:
<%@Language=VBscript%>
<%Response.Buffer=True%>
<html>
<body>
<% Public Sub RedirectMe
Response.Redirect("vote.asp?Validate=No")
End Sub
%>
<INPUT TYPE=BUTTON name="btnMine" VALUE="No" onClick="<%Call RedirectMe %>">
</body>
</html>
Can anyone suggest a possible solution? I've done a bit of a workaround where i use a button/form combo to redirect me to the desired page and while it works its not what I want. Any tips much appreciated
|
|
|
|
| Join OCAU to remove this ad! |
|
|
#2 |
|
<blank>
Join Date: Jun 2001
Location: Perth, WA
Posts: 5,345
|
That's never going to work, because you're using client-side scripting (the button onClick) to call server-side scripting (the RedirectMe sub).
You need to do it all with client-side scripting, because once the page has been loaded into the client browser, the ASP scripting cannot be accessed anymore....it's only executed when the web server is building the page. This will work: Code:
<input type="button" value="No" onClick="javascript:top.location.href='vote.asp?Validate=No'"> Martin. |
|
|
|
|
|
#3 |
|
Member
Join Date: Jun 2001
Location: Sydney
Posts: 4,202
|
Hi mpot,
Thanks for pointing me in the right direction. I went searching for the VBS alternative to JS' top.location.href and managed to get it working.
__________________
Last edited by xsive; 14th September 2002 at 1:28 PM. |
|
|
|
|
|
#4 |
|
Member
Join Date: Apr 2002
Location: Brisbane
Posts: 86
|
If you were to use the new asp.net then you would be able to use server side scripting. I'm only just new at it but i believe it would work something like this.
--------------------------------------------------------------------------------- <script language="VBSCript" runat="Server"> sub RedirectMe(byval pWhere) response.redirect pWhere end sub </script> <input type="button" value="Go Now" onclick="RedirectMe 'http://gosomewherenow.com'"> --------------------------------------------------------------------------------- I'm not really sure if that would work i was just trying to demonstrate the advantages of .net. I actually don't think you can use the response.redirect anymore ![]() There is another way of redirecting with vbscript (client side) --------------------------------------------------------------------------------- <script language="vbScript"> sub RedirectMe(byval pWhere) window.self.location = pWhere end sub </script> <input type="button" value="Go with vbScript" onclick="vbScript:RedirectMe 'Http://gosomewherenow.com'"> --------------------------------------------------------------------------------- I just thought i would give you a bit more infor and options. When doing client side scripting events like the onclick above. If you need to use both vbScript and Javascript on your page you will need to specify (as i have done) which language to use.
|
|
|
|
|
|
#5 |
|
Member
Join Date: Aug 2002
Location: Melbourne
Posts: 1,404
|
AFAIK, you would need "runat=server" on the input tag for that to work. ASP.NET needs to know that you want it to be a server event, not client.
__________________
-- Chicken |
|
|
|
![]() |
| Bookmarks |
|
Sign up for a free OCAU account and this ad will go away! |
| Thread Tools | |
|
|