473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="javas cript">
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 5480
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="javas cript">
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****@NOSPAMd evelop.com> wrote in message
news:15******** **************@ msnews.microsof t.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="javas cript">
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
905
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
7041
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 Complete() sub. This is within a page that will take me quite a while to test, so I'd like to know if I've got this right beforehand. I think I'm...
2
1128
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 event. Thanks for any help provied.
7
5715
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 the user controls to do a postback but not the rest of the page. Is this possible? it seems like it should be. If it is, please explain how I...
0
1380
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 button does postback now. I couldnt understand what isgoing on, can someone please help. I tried to set the 'enableviewstate' property to false, then...
1
1298
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 advance
2
635
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel? ----------------------------------------------------------------------- The buttons on a confirm box cannot be changed, nor can you specify a default button. However, you should be able to...
6
2425
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 2.0. The User is presented with an OK or Cancel confirmation window. However, pressing Cancel does not result in the button's post back being...
3
4219
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 information he entered and when user click confirm button only it should submit to the DB. Could you please tell me what is the best way? Do I need to...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.