473,396 Members | 1,666 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,396 software developers and data experts.

Cancel Postback for ASP.Net Button

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 cancelled. In the meantime,
I'll try the other suggested methods.

Here is my javscript:

function CheckForSave(thisButton) {

if (confirm("Appointment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==true) {
return true;
}
else {
return false;
}
}
Nov 12 '07 #1
6 2420
The button itself needs to have an onclick event handler that reads like
this:

onclick="return CheckForSave(this)"

Just returning true or false from the function isn't enough, you need to
have that return value itself returned to the onclick event handler.

"WhiskeyRomeo" <Wh**********@discussions.microsoft.comwrote in message
news:AB**********************************@microsof t.com...
>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 cancelled. In the
meantime,
I'll try the other suggested methods.

Here is my javscript:

function CheckForSave(thisButton) {

if (confirm("Appointment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==true) {
return true;
}
else {
return false;
}
}

Nov 12 '07 #2
In the InitializeComponent Sub which VS2005 creates for you when addinh
components to the Component Designer, I just needed to add this line:

Me.btnNewAppt.Attributes.Add("onclick", "return CheckForSave(this);")

This answers the question why it works in 1.1 but not 2.0.

Which begs the questions:

Which event is the best event to call this Initialize Component?

Why does 2.0 work this way? Is adding components not the preferred way
anymore?

WR

"WhiskeyRomeo" wrote:
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 cancelled. In the meantime,
I'll try the other suggested methods.

Here is my javscript:

function CheckForSave(thisButton) {

if (confirm("Appointment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==true) {
return true;
}
else {
return false;
}
}
Nov 12 '07 #3
Thanks for the quick reply. See my 2nd post. I still do not understand why
setting the onClientClick in the designer does not work. Isn't that the
purpose of it?
"Scott M." wrote:
The button itself needs to have an onclick event handler that reads like
this:

onclick="return CheckForSave(this)"

Just returning true or false from the function isn't enough, you need to
have that return value itself returned to the onclick event handler.

"WhiskeyRomeo" <Wh**********@discussions.microsoft.comwrote in message
news:AB**********************************@microsof t.com...
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 cancelled. In the
meantime,
I'll try the other suggested methods.

Here is my javscript:

function CheckForSave(thisButton) {

if (confirm("Appointment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==true) {
return true;
}
else {
return false;
}
}


Nov 12 '07 #4
the designer works fine if you follow directions:

onclientclick="return CheckForSave(this);"

would work as well as setting the onclick attribute (as thats all
onclientclick does).

why you need the retun:

whent the browsers sees onclick="CheckForSave(this)" it generates an
anonymous function to execute the code and assigns as the click handler. when
it executes the click handler it checks the return value of the anonymous
function:

// returns void
button.click = function(){ CheckForSave(this); }

// returns function result
button.click = function(){ return CheckForSave(this); }




-- bruce (sqlwork.com)
"WhiskeyRomeo" wrote:
In the InitializeComponent Sub which VS2005 creates for you when addinh
components to the Component Designer, I just needed to add this line:

Me.btnNewAppt.Attributes.Add("onclick", "return CheckForSave(this);")

This answers the question why it works in 1.1 but not 2.0.

Which begs the questions:

Which event is the best event to call this Initialize Component?

Why does 2.0 work this way? Is adding components not the preferred way
anymore?

WR

"WhiskeyRomeo" wrote:
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 cancelled. In the meantime,
I'll try the other suggested methods.

Here is my javscript:

function CheckForSave(thisButton) {

if (confirm("Appointment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==true) {
return true;
}
else {
return false;
}
}
Nov 12 '07 #5
That make sense but . . .
maybe someone has to represent the 2% -- here are the instructions I have:

http://msdn2.microsoft.com/en-us/lib...ientclick.aspx

It says put the name of the javacript function to be called not "return
[name of javascript function]" One has to scroll all the way down to the
last commient in Community Content section to see those "directions."
wr

"bruce barker (sqlwork.com)" wrote:
the designer works fine if you follow directions:

onclientclick="return CheckForSave(this);"

would work as well as setting the onclick attribute (as thats all
onclientclick does).

why you need the retun:

whent the browsers sees onclick="CheckForSave(this)" it generates an
anonymous function to execute the code and assigns as the click handler. when
it executes the click handler it checks the return value of the anonymous
function:

// returns void
button.click = function(){ CheckForSave(this); }

// returns function result
button.click = function(){ return CheckForSave(this); }




-- bruce (sqlwork.com)
"WhiskeyRomeo" wrote:
In the InitializeComponent Sub which VS2005 creates for you when addinh
components to the Component Designer, I just needed to add this line:

Me.btnNewAppt.Attributes.Add("onclick", "return CheckForSave(this);")

This answers the question why it works in 1.1 but not 2.0.

Which begs the questions:

Which event is the best event to call this Initialize Component?

Why does 2.0 work this way? Is adding components not the preferred way
anymore?

WR

"WhiskeyRomeo" wrote:
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 cancelled. In the meantime,
I'll try the other suggested methods.
>
Here is my javscript:
>
function CheckForSave(thisButton) {
>
if (confirm("Appointment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==true) {
return true;
}
else {
return false;
}
}
Nov 12 '07 #6
The instructions discuss how to add an event handler to a piece of client
side code, but adding the extra "return" is not really related to adding
event handlers, it's something you've just got to know about JavaScript.

If you look at the description of the help topic "Gets or sets the
client-side script that executes when a Button control's Click event is
raised.", you'll note that it doesn't say "...and how to cancel an event
that has already been triggered." - - That's a completely different issue.

-Scott
"WhiskeyRomeo" <Wh**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
That make sense but . . .
maybe someone has to represent the 2% -- here are the instructions I have:

http://msdn2.microsoft.com/en-us/lib...ientclick.aspx

It says put the name of the javacript function to be called not "return
[name of javascript function]" One has to scroll all the way down to the
last commient in Community Content section to see those "directions."
wr

"bruce barker (sqlwork.com)" wrote:
>the designer works fine if you follow directions:

onclientclick="return CheckForSave(this);"

would work as well as setting the onclick attribute (as thats all
onclientclick does).

why you need the retun:

whent the browsers sees onclick="CheckForSave(this)" it generates an
anonymous function to execute the code and assigns as the click handler.
when
it executes the click handler it checks the return value of the anonymous
function:

// returns void
button.click = function(){ CheckForSave(this); }

// returns function result
button.click = function(){ return CheckForSave(this); }




-- bruce (sqlwork.com)
"WhiskeyRomeo" wrote:
In the InitializeComponent Sub which VS2005 creates for you when addinh
components to the Component Designer, I just needed to add this line:

Me.btnNewAppt.Attributes.Add("onclick", "return
CheckForSave(this);")

This answers the question why it works in 1.1 but not 2.0.

Which begs the questions:

Which event is the best event to call this Initialize Component?

Why does 2.0 work this way? Is adding components not the preferred way
anymore?

WR

"WhiskeyRomeo" wrote:

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 cancelled. In the
meantime,
I'll try the other suggested methods.

Here is my javscript:

function CheckForSave(thisButton) {

if (confirm("Appointment Will Be Saved. Check Current Appointment
box and
make sure it is correct. If so, you may navigate away or close your
browser.")==true) {
return true;
}
else {
return false;
}
}

Nov 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: amrita | last post by:
hi i have a table in web form wth name table1.i need that wen i click on cancel button all the textboxes in that table becomes empty.ny ideas how to do it,doin in onclien side wud be greatly...
1
by: moondaddy | last post by:
I have a datalist that makes use of the edit template. In this template I also have client side validation controls for required fields. My problem is that when I click on the cancel button it...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
3
by: pmud | last post by:
Hi, I have an ASP.NET application using C# code. I am using a datagrid to display records from a database based on a user input, i.e a user enters a compnay name in text box & when he clicks a...
1
by: Bucky | last post by:
I haven't found any vbscript code that can stop the form submission/postback after the msgbox. The problem is that asp:button is rendered as <input type="submit"> instead of <input type="button">....
3
by: lakshmikandhan | last post by:
Hi All, Can anyone tell how to handle the Cancel button in the JavaScript Confirm() method?If we press cancel, I have to perform certain action in the Server side? Plz help me!! Thanx, Jacob.
4
by: =?Utf-8?B?T3Bh?= | last post by:
Hi, I'm not sure if the title is correct. Here's what I am having trouble with: I have a server side button control where I am calling a javascript function via the OnClientClick property. I...
0
by: Eraser | last post by:
Hi to all .NET guru guys... I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
1
BeemerBiker
by: BeemerBiker | last post by:
I am using CancelAsyncPostback in an attempt to stop a page from loading. It actually works (the page wont get a postback) but the server keeps running, processing data I dont want processed until...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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...
0
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,...

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.