Connecting Tech Pros Worldwide Forums | Help | Site Map

Basic Script Not Working in ASP.Net Page

Guest
 
Posts: n/a
#1: Jan 9 '06
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










Henrique Mello
Guest
 
Posts: n/a
#2: Jan 9 '06

re: Basic Script Not Working in ASP.Net Page


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

Karl Seguin
Guest
 
Posts: n/a
#3: Jan 9 '06

re: Basic Script Not Working in ASP.Net Page


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

--
MY ASP.Net tutorials
http://www.openmymind.net/


<rlrcstr@newsgroups.nospam> wrote in message
news:OfEJ$WVFGHA.3944@tk2msftngp13.phx.gbl...[color=blue]
> 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
>
>
>
>
>
>
>
>
>[/color]


Guest
 
Posts: n/a
#4: Jan 9 '06

re: Basic Script Not Working in ASP.Net Page


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



<rlrcstr@newsgroups.nospam> wrote in message
news:OfEJ$WVFGHA.3944@tk2msftngp13.phx.gbl...[color=blue]
> Looking to do something pretty simple... I have a cancel button on my[/color]
page.[color=blue]
> 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[/color]
procedure[color=blue]
> and call it in response to an onclick event, the redirect never happens.[/color]
I[color=blue]
> 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[/color]
page?[color=blue]
> Thanks.
>
> Jerry
>
>
>
>
>
>
>
>
>[/color]


Henrique Mello
Guest
 
Posts: n/a
#5: Jan 9 '06

re: Basic Script Not Working in ASP.Net Page


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

Guest
 
Posts: n/a
#6: Jan 9 '06

re: Basic Script Not Working in ASP.Net Page


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.

"Henrique Mello" <hmello@gmail.com> wrote in message
news:1136838766.610022.233060@g47g2000cwa.googlegr oups.com...[color=blue]
> Well, you have to make if a function that return false always to the
> event so the post back wont happen
>[/color]


Closed Thread