confirm does not cancel postback?

J

JerryK

I have a piece of asp.net code that sets up a call to a javascript function
in a controls onclick event. This javascript function displays a confirm
dialog and returns the results of the confirm dialog. However, of the user
presses "Cancel" in the confirm dialog, which should return false and cause
the postback to be aborted. However, the postback continues and the Asp.Net
OnClick event handler is called. Anyone know why this happening?

Here is an outline of the code:

a.ascx.vb

.....
Page_load()

if not page.ispostback then
route.attribute("onclick", "MyValidator();")
end if
....

sub route_click(....) handles route.click

I WAS NOT EXPECTING TO GET TO HERE, BUT IT DOES
....
end sub

a.ascx
....

<script language="javascript">
function MyValidator()
{
if(document.all["mycontrol"].value = '')
{ return confirm("a value must be entered"); } THIS IS
DISPLAYED AND Cancel IS PRESSED
else
{ return true; }
}
</script>


Any thoughts,

Jerry
 
B

Brock Allen

Change:
route.attribute("onclick", "MyValidator();")

To:

route.attribute("onclick", "return MyValidator();")




I have a piece of asp.net code that sets up a call to a javascript
function in a controls onclick event. This javascript function
displays a confirm dialog and returns the results of the confirm
dialog. However, of the user presses "Cancel" in the confirm dialog,
which should return false and cause the postback to be aborted.
However, the postback continues and the Asp.Net OnClick event handler
is called. Anyone know why this happening?

Here is an outline of the code:

a.ascx.vb

....
Page_load()
if not page.ispostback then
route.attribute("onclick", "MyValidator();")
end if
....
sub route_click(....) handles route.click

I WAS NOT EXPECTING TO GET TO HERE, BUT IT DOES
...
end sub
a.ascx
...
<script language="javascript">
function MyValidator()
{
if(document.all["mycontrol"].value = '')
{ return confirm("a value must be entered"); } THIS IS
DISPLAYED AND Cancel IS PRESSED
else
{ return true; }
}
</script>
Any thoughts,

Jerry
 
J

JerryK

Doooh....

I feel so dumb!

Thanks you!


Brock Allen said:
Change:
route.attribute("onclick", "MyValidator();")

To:

route.attribute("onclick", "return MyValidator();")




I have a piece of asp.net code that sets up a call to a javascript
function in a controls onclick event. This javascript function
displays a confirm dialog and returns the results of the confirm
dialog. However, of the user presses "Cancel" in the confirm dialog,
which should return false and cause the postback to be aborted.
However, the postback continues and the Asp.Net OnClick event handler
is called. Anyone know why this happening?

Here is an outline of the code:

a.ascx.vb

....
Page_load()
if not page.ispostback then
route.attribute("onclick", "MyValidator();")
end if
....
sub route_click(....) handles route.click

I WAS NOT EXPECTING TO GET TO HERE, BUT IT DOES
...
end sub
a.ascx
...
<script language="javascript">
function MyValidator()
{
if(document.all["mycontrol"].value = '')
{ return confirm("a value must be entered"); } THIS IS
DISPLAYED AND Cancel IS PRESSED
else
{ return true; }
}
</script>
Any thoughts,

Jerry
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top