473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 5473
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SamIAm | last post by:
Hi I would like to call a JavaScript function before my ImageButton fires a postback. Only ff the function returns true the ImageButon will fire the postback? Any ideas S
2
by: Kathy Burke | last post by:
I'm trying to use the following code to use a javascript return confirm. Cancel would exit the sub and return the page to its history (-2). OK would proceed with the asp.net code, i.e., run the...
2
by: Erick | last post by:
Hi, Is there any way that I can know the object that does fires or does postback to the page on the Page_Load event. I tried to use the sender object that is defined as parameter into this...
7
by: moondaddy | last post by:
I'm building a page in vb.net with several user controls on it. I'm using user controls instead of a frames page since I've seen this recommended many times in this user group. I want just one of...
0
by: Ganesh Raju via .NET 247 | last post by:
Hi, I have a dropdownlist and a button on my aspx page. If i havemore than 90 items in the dropdownlist my button does not dopostback. If there are less than 80 items in the dropdownlist,same...
1
by: nigeaman | last post by:
Hi, There seems to be a problem with the validator controls and Atlas June CTP. The update panel is posting back to the server even if a control fails validation. Any ideas ? Thanks in...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel?...
6
by: =?Utf-8?B?V2hpc2tleVJvbWVv?= | last post by:
I read the 4 or 5 threads on this Subject and it seems my javasript should work but it doesn't. In the designer, the onClientClick is set to: CheckForSave(this). This works in .Net 1.1 but not...
3
by: ghjk | last post by:
I have a web page which is used to enter user data. In there I have 4 buttons named as "Submit, Confirm,Edit,Cancel". User should enter data and click "Submit " button. Then I want to display all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.