473,396 Members | 2,004 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 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 11889
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*******@gmail.comwrote in message
news:11*********************@s34g2000cwa.googlegro ups.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
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....
3
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...
2
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...
0
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...
21
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...
1
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,...
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: 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...
13
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...
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: 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
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: 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
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,...
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
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.