473,659 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cancel a click event on a button

Hi, I'm making a dialog form with a textbox and 2 buttons: OK and
Cancel.

I want when I click on OK button, the program check the textbox, and if
there is any error in the text introduced there, then it shows a
MessageBox and cancel the click event, so the dialog form won't close.

How can I cancel the click event on a button? I have looked at
"EventArgs e", but it hasnt any property to cancel the vent.

Thank you! :)
Jose.

Jan 17 '07 #1
3 11930
You don't need to cancel the click event.
I would do like this:
Handle the textbox validation event. If there are some error then just
inform the user, otherwise set the form's DialogResult property to Ok.
Do it manually without setting it visually, otherwise it will always close.

HTH
Fabrizio

"Gallarpri" <ga*******@gmai l.comwrote in message
news:11******** *************@s 34g2000cwa.goog legroups.com...
Hi, I'm making a dialog form with a textbox and 2 buttons: OK and
Cancel.

I want when I click on OK button, the program check the textbox, and if
there is any error in the text introduced there, then it shows a
MessageBox and cancel the click event, so the dialog form won't close.

How can I cancel the click event on a button? I have looked at
"EventArgs e", but it hasnt any property to cancel the vent.

Thank you! :)
Jose.

Jan 17 '07 #2
Thanks for answering.

I have finally resolved it putting the DialogResult property of the OK
button to "None", so the form doesnt close now when I click on this
button. I do the check, and if all its correct, then I call
this.Close()

Hope it helps to someone too :)

Jan 17 '07 #3
Gallarpri wrote:

[...snip...]
I have finally resolved it putting the DialogResult property of the OK
button to "None", so the form doesnt close now when I click on this
button. I do the check, and if all its correct, then I call
this.Close()
[...snip...]

As Fabrizio mentioned, set the DialogResult property of your Form to
DialogResult.OK before closing, so you can find out wether your user clicked
on "OK" or "Cancel"... .

Jan 18 '07 #4

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

Similar topics

5
2036
by: Verde | last post by:
I'm using a 3rd party component in an ASP.NET 1.1 Web application. The component has a .Click event that can be fired from the client, with an associated event procedure in the code-behind module. The logic in the click event procedure may, under some conditions, need to abort further processing. AFAIK the control's event is not cancellable. At least its EventArgs does not have any apparent support for .Cancel. So, what can I do to...
3
2770
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set the value to False, but I would have expected it to be False on entry. TIA Charles
2
3287
by: Bob | last post by:
In a winform with a datagridview using cellvalidating event but also have a save button that is located on a tablebindignnavigator. The behaviour I observe is that if the cellvalidating issues a cancel = true after the save button has been clicked, the update statements in the click event of the save button still occur but nothing gets saved, which is OK. Except that I pop a message box in the click event after the update statements have...
0
1698
by: Stuart Whiteford | last post by:
Hi, I've got a basic web form, two textboxes, a couple of radio button groups, some required field validators, and a Submit and Cancel button. When the page loads, if I click the Cancel button, the server-side event fires as normal. However, if I click the Submit button (with no information entered) the client-side validators fire, but if I then decide to press the Cancel
21
9156
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
1
3903
by: Sergey Zuyev | last post by:
Hello all I have simple edit form. When user saves data that contains restricted characters such as (< , etc.) , regular expression validator will display a warning message. It all works fine, but if users decides to exit the form using Cancel button then error occurs: A potentially dangerous Request.Form value was detected from the client. The Cancel button has CausesValidation set to false. Is there any way to avoid this error...
6
2428
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 cancelled. In the meantime, I'll try the other suggested methods. Here is my javscript: function...
3
3289
by: nareshreddy | last post by:
Hi i am using the below code to close the window and i l get promt when click on 'X' button on ie browser with OK and Cancel buttons. if i click ok window will be closed, if i click cancel window wont close. what i need is if i click ok also it should perform as a cancel and the window should not close. thanks in advance. <SCRIPT FOR = "window" EVENT = "onbeforeunload"> event.returnValue = "If you wish to keep this session...
13
10555
Frinavale
by: Frinavale | last post by:
I've been trying all morning to cancel a form submit to the server. I have a JavaScript Object that determines whether or not the page should be submitted to the server depending on whether the user clicks "yes" or "no". This Object is attached to various HTML elements on the page (buttons, selects etc) and traps any events that they raise that cause the page to submit. If the user has not responded, the Object should cancel the page...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5649
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
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
1737
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.