473,699 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(th is). 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(th isButton) {

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

onclick="return CheckForSave(th is)"

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.

"WhiskeyRom eo" <Wh**********@d iscussions.micr osoft.comwrote in message
news:AB******** *************** ***********@mic rosoft.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(th is). 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(th isButton) {

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

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

Me.btnNewAppt.A ttributes.Add(" onclick", "return CheckForSave(th is);")

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

"WhiskeyRom eo" 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(th is). 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(th isButton) {

if (confirm("Appoi ntment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==tru e) {
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(th is)"

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.

"WhiskeyRom eo" <Wh**********@d iscussions.micr osoft.comwrote in message
news:AB******** *************** ***********@mic rosoft.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(th is). 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(th isButton) {

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


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

onclientclick=" return CheckForSave(th is);"

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

why you need the retun:

whent the browsers sees onclick="CheckF orSave(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(th is); }

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




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

Me.btnNewAppt.A ttributes.Add(" onclick", "return CheckForSave(th is);")

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

"WhiskeyRom eo" 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(th is). 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(th isButton) {

if (confirm("Appoi ntment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==tru e) {
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(th is);"

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

why you need the retun:

whent the browsers sees onclick="CheckF orSave(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(th is); }

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




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

Me.btnNewAppt.A ttributes.Add(" onclick", "return CheckForSave(th is);")

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

"WhiskeyRom eo" 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(th is). 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(th isButton) {
>
if (confirm("Appoi ntment Will Be Saved. Check Current Appointment box and
make sure it is correct. If so, you may navigate away or close your
browser.")==tru e) {
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
"WhiskeyRom eo" <Wh**********@d iscussions.micr osoft.comwrote in message
news:72******** *************** ***********@mic rosoft.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(th is);"

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

why you need the retun:

whent the browsers sees onclick="CheckF orSave(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(th is); }

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




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

Me.btnNewAppt.A ttributes.Add(" onclick", "return
CheckForSave(th is);")

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

"WhiskeyRom eo" 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(th is). 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(th isButton) {

if (confirm("Appoi ntment Will Be Saved. Check Current Appointment
box and
make sure it is correct. If so, you may navigate away or close your
browser.")==tru e) {
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
1563
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 apppreciated thnx amrita
1
1891
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 won't do a postback to cancel the update when the form's not valid. How can I bypass the validation for the cancel button? -- moondaddy@nospam.com
7
3698
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 satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again. The app I've written has three ASPX pages. One is a combined page which writes a little text...
3
2280
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 "Submit" button, only those records are displayed where company name matches with user input. I need the datagrid to be editable. For this i used the walkthrough from ..NET "Using a datagrid for reading & writing data to database" or it was some...
1
3951
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">. So instead of doing a "document.form(0).submit" upon "Yes", I need to stop the form submission upon "No". Javascript is easy since you can do "return confirm...", but I'm looking for a vbscript solution. Here's my relevant code: <asp:button...
3
2081
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
8871
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 also have a server side event handler to handle the On_Click event on the postback. I wish to cancel the postback based on whether the javascript function returns true or false. The problem is that the I never get a postback and ofcourse the...
0
2810
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. What happened is if I select cancel on my confirmation button, it executes the griedview postback which i assigned in my code behind. Please see my codes below... Code beind: protected void gvDefectCatalog_RowDataBound(object sender,...
1
2321
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 it gets done with a task I really didnt want done because I didnt realize how long it took I tried adding a button to do a server transfer to "./Default.aspx" but it only transfered AFTER the processing was complete. what I tried that didnt work...
0
8618
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8885
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7752
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4376
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.