Basic Script Not Working in ASP.Net Page

G

Guest

Looking to do something pretty simple... I have a cancel button on my page.
When the user clicks it, i want to verify they want to cancel and if so,
redirect them.

Code:
-------------------------------------------------------------
<html>
<script language=vbscript>
if MsgBox("Testing",4) = 6 Then
window.location = "http://www.google.com"
End if
</script>
</html>
--------------------------------------------------------------

This code works just fine like that, but when I place it in a sub procedure
and call it in response to an onclick event, the redirect never happens. I
even placed an alert box in the if block ot verify that I was getting into
the block. I got the alert, but no redirect. Why doesn't this work in
repsonse to an onclick event, but it deos work by itself in a separate page?
Thanks.

Jerry
 
K

Karl Seguin

Are you talking about an actual server-side onClick event handler in
ASP.NET?

Your code is running client-side, instead of using JavaScript, you are using
VBScript, but it's still client-side (running in the browser). A server
side method can't call a client-side one.

Karl
 
H

Henrique Mello

well, this should be on a javascript thread but I aswer you
do a return false to the event, cause the button is posting the form
the and redirect is never happening
 
G

Guest

Karl - This is supposed to be client side stuff. There is no need to post
back to the server if the client is not interested in canceling the
transaction. The onclick event is calling a client side sub defined in a
script block.

Henrique - This is being done in vbscript because the javascript
confirmation dialog doesn't allow you to specify the text on the buttons and
it can get confusing for an end user to confirm cancelation with an Okay
button and Cancel cancelation with a "Cancel" button which is what they used
to get the confirmation window to begin with. With the vbscript messagebox
I can display Yes and No buttons instead.

So the problem seems to be that the input element is causing a postback
which is canceling the redirect?

Is there a way in VBscript to keep this from happening so I can keep my Yes
and No buttons.

I'm really not interested in creating a custom dialog for this so I can make
it more user friendly with javascript...

Thanks for the responses.

Jerry
 
H

Henrique Mello

Well, you have to make if a function that return false always to the
event so the post back wont happen
 
G

Guest

Right... But I can't seem to find a way to make that happen in VBScript.
I've worked around it by having a JavaScript function call the VBScript
function.

The VBScript shows the dialog the way I want it to appear and the JavaScript
returns the value the way the browser needs it.

A bit klunky, perhaps, but it works.
 

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

Top