Click event not raised when clicking a button after displaying a dialog box

Click event not raised when clicking a button after displaying a dialog box

Post by Natalya.Pi » Thu, 07 Dec 2006 01:09:57

Hello,

In the Validating event of a TextBox, I am displaying a Yes/No message
box. If clicked on No, I cancel any subsequent events. This works
just fine. If clicked Yes, I want to go on. This doesn't work if I
click on a button (like a Save button). The focus stays with the Save
button after clicking Yes, but the click event for the Save button
doesn't fire.

I've pasted the condensed version of my code below. As a work around,
I tried setting "this.ActiveControl = this.ActiveControl;" but it had
no effect. This was suggested for a somewhat different problem by an
older post:
http://www.yqcomputer.com/ %238a8f5e8058e96ef0

private void txtQty_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (Convert.ToInt32(txtQty.Text) == 0)
{
if (MessageBox.Show("Are you sure you want quantity set
to zero?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
//this.ActiveControl = this.ActiveControl;
}
else
{
e.Cancel = true;
}
}
}

I use VS2003.

Thanks.