473,761 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MessageBox in Validating event cancels subsequent events

Hi,

It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2's click event doesn't fire
if you open a dialog box in button 1's validating event. Am I doing
something wrong here?
Thanks
Al

Imports system
Imports system.windows. forms
' Create a form, add two buttons and event handlers.
' Click on Button 2 to receive Button 1 validating
' event but not button 2's click event. MessageBox
' appears to kill the click event.
Module ValidateTest
Sub Main()
Dim frm As New Form()
Dim btn As New Button
btn.Text = "One"
btn.Parent = frm
AddHandler btn.Validating, AddressOf BtnValidating

btn = New Button
btn.Left = btn.Width + 3
btn.Text = "Two"
btn.Parent = frm
AddHandler btn.Click, AddressOf BtnClick

Application.Run (frm)
End Sub

Private Sub BtnValidating(B yVal sender As Object,
ByVal e As System.Componen tModel.CancelEv entArgs)
MessageBox.Show ("BtnValidat ing event")
End Sub

Private Sub BtnClick(ByVal sender As Object, ByVal e As
System.EventArg s)
MessageBox.Show ("BtnClick event")
End Sub
End Module

Aug 9 '06 #1
16 5510
Al Santino wrote:
It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2's click event doesn't fire
if you open a dialog box in button 1's validating event. Am I doing
something wrong here?
I'm not sure I understand the problem. Why would the second button's
click event be fired when the Validating event for button 1 fires?
>
<code snipped>
Aug 9 '06 #2
"Chris Dunaway" <du******@gmail .comwrote in message
news:11******** **************@ n13g2000cwa.goo glegroups.com.. .
Al Santino wrote:
>It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2's click event doesn't
fire
if you open a dialog box in button 1's validating event. Am I doing
something wrong here?

I'm not sure I understand the problem. Why would the second button's
click event be fired when the Validating event for button 1 fires?
>>
<code snipped>
Well, I thought it would fire because that was how it's supposed to work.

If you remove the MessageBox call in the validation handler the click event
fires for button 2. My understanding is that the second button's event
should fire unless you set the cancel arg to true in the validation event
handler.

Aug 9 '06 #3

"Chris Dunaway" <du******@gmail .comwrote in message
news:11******** **************@ n13g2000cwa.goo glegroups.com.. .
Al Santino wrote:
>It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2's click event doesn't
fire
if you open a dialog box in button 1's validating event. Am I doing
something wrong here?

I'm not sure I understand the problem. Why would the second button's
click event be fired when the Validating event for button 1 fires?
>>
<code snipped>
Actually I'm not suggesting it should fire WHEN the validating event fires
but AFTER it fires since the validating event didn't set the cancel argument
to true.
Aug 9 '06 #4
Al Santino wrote:
Actually I'm not suggesting it should fire WHEN the validating event fires
but AFTER it fires since the validating event didn't set the cancel argument
to true.
Perhaps I misunderstood. Are you saying that after the validating
event fires, then the click event for the button doesn't fire, even if
you click the button?

Aug 9 '06 #5
"Chris Dunaway" <du******@gmail .comwrote in message
news:11******** **************@ n13g2000cwa.goo glegroups.com.. .
Al Santino wrote:
>Actually I'm not suggesting it should fire WHEN the validating event
fires
but AFTER it fires since the validating event didn't set the cancel
argument
to true.

Perhaps I misunderstood. Are you saying that after the validating
event fires, then the click event for the button doesn't fire, even if
you click the button?
Yes. If you run the program, button 1 will start with the focus. If you
click on button 2, the button 1 validating event will fire and the program
will display the messagebox. After you close the message box, button 2 will
get the focus but its click event will not fire.
Aug 9 '06 #6
"Chris Dunaway" <du******@gmail .comwrote in message
news:11******** **************@ n13g2000cwa.goo glegroups.com.. .
Al Santino wrote:
>Actually I'm not suggesting it should fire WHEN the validating event
fires
but AFTER it fires since the validating event didn't set the cancel
argument
to true.

Perhaps I misunderstood. Are you saying that after the validating
event fires, then the click event for the button doesn't fire, even if
you click the button?
Or better put:

Yes. If you run the program, button 1 will start with the focus. If you
click on button 2, the button 1 validating event will fire and the program
will display the messagebox. After you close the message box, button 2 will
get the focus but its click event will not _have fired_.
Aug 9 '06 #7
Hello, Al,

I have tried your code (VB.Net 2003) and can confirm that I see the same
(inappropriate) behaviour.

It sure looks like a problem to me. I hope someone can provide an
explanation and/or workaround.

Cheers,
Randy
Al Santino wrote:
Hi,

It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2's click event doesn't fire
if you open a dialog box in button 1's validating event. Am I doing
something wrong here?
Thanks
Al

Imports system
Imports system.windows. forms
' Create a form, add two buttons and event handlers.
' Click on Button 2 to receive Button 1 validating
' event but not button 2's click event. MessageBox
' appears to kill the click event.
Module ValidateTest
Sub Main()
Dim frm As New Form()
Dim btn As New Button
btn.Text = "One"
btn.Parent = frm
AddHandler btn.Validating, AddressOf BtnValidating

btn = New Button
btn.Left = btn.Width + 3
btn.Text = "Two"
btn.Parent = frm
AddHandler btn.Click, AddressOf BtnClick

Application.Run (frm)
End Sub

Private Sub BtnValidating(B yVal sender As Object,
ByVal e As System.Componen tModel.CancelEv entArgs)
MessageBox.Show ("BtnValidat ing event")
End Sub

Private Sub BtnClick(ByVal sender As Object, ByVal e As
System.EventArg s)
MessageBox.Show ("BtnClick event")
End Sub
End Module
Aug 10 '06 #8
Hi Randy,

Thanks for taking the time to try it. I'll keep my fingers crossed about
the workaround.

Al

"R. MacDonald" <sc****@NO-SP-AMcips.cawrote in message
news:44******** **************@ news.wanadoo.nl ...
Hello, Al,

I have tried your code (VB.Net 2003) and can confirm that I see the same
(inappropriate) behaviour.

It sure looks like a problem to me. I hope someone can provide an
explanation and/or workaround.

Cheers,
Randy
Al Santino wrote:
>Hi,

It appears displaying a messagebox in a validating event will cancel the
subsequent event. In the program below, button 2's click event doesn't
fire if you open a dialog box in button 1's validating event. Am I doing
something wrong here?
Thanks
Al

Imports system
Imports system.windows. forms
' Create a form, add two buttons and event handlers.
' Click on Button 2 to receive Button 1 validating
' event but not button 2's click event. MessageBox
' appears to kill the click event.
Module ValidateTest
Sub Main()
Dim frm As New Form()
Dim btn As New Button
btn.Text = "One"
btn.Parent = frm
AddHandler btn.Validating, AddressOf BtnValidating

btn = New Button
btn.Left = btn.Width + 3
btn.Text = "Two"
btn.Parent = frm
AddHandler btn.Click, AddressOf BtnClick

Application.Run (frm)
End Sub

Private Sub BtnValidating(B yVal sender As Object,
ByVal e As System.Componen tModel.CancelEv entArgs)
MessageBox.Show ("BtnValidat ing event")
End Sub

Private Sub BtnClick(ByVal sender As Object, ByVal e As
System.EventAr gs)
MessageBox.Show ("BtnClick event")
End Sub
End Module

Aug 10 '06 #9
Al Santino wrote:
"Chris Dunaway" <du******@gmail .comwrote in message
news:11******** **************@ n13g2000cwa.goo glegroups.com.. .
>>Al Santino wrote:

>>>Actually I'm not suggesting it should fire WHEN the validating event
fires
but AFTER it fires since the validating event didn't set the cancel
argument
to true.

Perhaps I misunderstood. Are you saying that after the validating
event fires, then the click event for the button doesn't fire, even if
you click the button?

Or better put:

Yes. If you run the program, button 1 will start with the focus. If you
click on button 2, the button 1 validating event will fire and the program
will display the messagebox. After you close the message box, button 2 will
get the focus but its click event will not _have fired_.


From the code posted I don't see why button2's click event would be
triggered at all. The click event will not fire simply because a button
get's the focus.

--
Rinze van Huizen
C-Services Holland b.v
Aug 11 '06 #10

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

Similar topics

2
9756
by: Paolo Mancini | last post by:
Hi all, I have a page with many different elements: <a href="...."> ... </a>, listboxes, radiobuttons, etc. Can I use javascript to prevent the user from interacting with the page? That is: can I intercept, alert the user, and cancel any click event on the page? Unfortunately, if the user clicks on a page element, the event bubbles
7
2516
by: MLH | last post by:
I tried the following code to prevent a checkbox from being updated (going from a value of Null to True, from True to False or from False to True). I was surprised it did not work. Can anyone offer a sensible, logical, insightful reason as to why Microsoft does not want to let programmers stop this event? Private Sub NoOwnerInfoChkBox_Click() If CurrentVehicleJobID = 0 Then
0
1609
by: Bradley Bossard via DotNetMonster.com | last post by:
I am having an issue with the .NET framework (or C#) and validating events. I have implemented several validating event handlers for textboxes on a form. When I run the app, the form works correctly the first time, but if I input some data in the form and click another control to change focus, the validator fires, but if I continue to hit 'ESC' enough times, it eventually lets me out of the validating loop and moves focus to the other...
0
1551
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another control which had it's causes validation property set to true however if I tabbed on to this control the event wouldn't fire. So after playing around with my code I figured out how to get it to work. I am not sure what the reason behind it is but it...
7
1759
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its events do this for me, but my extended textbox doesn't get created by those wonderful form setup wizards. So, 1) Is there a way I can pick up these events without having to code for each control and without using custom extended controls, OR
21
9220
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.
4
3008
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by another when its form Closing routine is run? I guess what I'm asking is will that work. If one form sets e.cancelled to true will e.cancel be true when the next form receives a closing event?
3
1975
by: Hamed | last post by:
Hello I have a Data Entry Form having some controls including a TextBox. When the user types an entry, I query a table and if it was entered before, I ask the user (using ShowModal method of a custom message form) if he wants to see his old entry in a new form. if he/she choose Yes, I create a new form and show the previously entered data in it. The problem is when I create and show the new form, the validating event is fired two...
2
2682
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly how can i tell that those events have finished so that i can test for a new situation. My problem is i am modding some existing code, were the TAB key keypress is captured by a external c# module.
0
9554
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
9377
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
9989
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
9925
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
8814
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...
0
6640
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
5266
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...
1
3913
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
3
2788
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.