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

  • Thread starter Natalya.Pinsker
  • Start date
N

Natalya.Pinsker

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://groups.google.com/group/micr...6a4d5900e11/8a8f5e8058e96ef0#8a8f5e8058e96ef0

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.
 
G

Guest

Why not just call the Save event method directly if the dialog result answer
is "Yes"?

MK
 
N

NP

It doesn't have to be the Save button. In fact, it can be any button
on the form, including buttons in this or other user controls.

Is this a problem with .NET framework?

Thanks,
NP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top