469,903 Members | 1,944 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

confirm does not cancel postback?

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
Nov 19 '05 #1
2 5390
Change:
route.attribute("onclick", "MyValidator();")
To:

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

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #2
Doooh....

I feel so dumb!

Thanks you!
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:15**********************@msnews.microsoft.com ...
Change:
route.attribute("onclick", "MyValidator();")


To:

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

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Erick | last post: by
reply views Thread by Ganesh Raju via .NET 247 | last post: by
1 post views Thread by nigeaman | last post: by
6 posts views Thread by =?Utf-8?B?V2hpc2tleVJvbWVv?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.