The Validating event for a wizardpage

Wizard for Windows Forms Forum

Posted 18 years ago by Kasper
Avatar
Hi,

I have a set of wizardpages, and on one of them, I use the Validating event to check a single TextBox. Now, when the user tries to press Next, i present them with a textbox to instruct them to fill out the field, and set the Cancel property to true. This works fine. However, if the user presses the Back button instead, the event is fired 3 times, giving my user 3 messageboxes, and despite the Cancel still being set to false, the page is changed to the previous page anyway! Now, if the user tries to move forward to actually fill the textbox, he is not allowed to, which makes it really hard to escape the dialog hehe :). Am I doing something wrong here, or is there a bug in the Wizard control?

Comments (7)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Can you build and email over a simple project that shows this so we can debug it and see where the problem lies? Thanks!


Actipro Software Support

Posted 18 years ago by Kasper
Avatar
It's very easy to replicate, just try the following:

Add 3 pages to a Wizard control. The first should be a Welcome page, the 2 others can just be Interior pages. On the middle page, add a textbox, and add the following code to it's Validating event:

if(textBox1.Text == String.Empty)
{
    e.Cancel = true;
    MessageBox.Show("Error while validating the textbox on the second page!");
}
Now run and go to the second page, then click Back. You should hopefully see the problem :)
Posted 18 years ago by Kasper
Avatar
Any news on this subject? I would very much like to get it fixed for next beta version of my application :)
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
A little... We've put several hours into this and have found some workarounds.

A major problem is that Microsoft has encapsulted all their validation code within the framework except for a couple exposed methods. The .NET validation code exhibits odd behavior sometimes and it's difficult to figure out what Microsoft was thinking.

Odd thing #1:
Controls will not validate until they get focus. So go to the second page but add a second textbox that receives focus first and doesn't have validation code. If you run it, and keep hitting Next, validation never kicks off on the one textbox since it never got focus. We don't like how this is designed by Microsoft. Validation should kick off on all child controls, regardless of whether they got focus.

Odd thing #2:
Why is the validation code being called on the textbox after you go back to the first page and press Next. If you look at the stack trace, our code isn't even being called in that. The parent page is invisible too. It doesn't make any sense.

Ok now for workarounds... first in your TextBox.Validating event handler, add a check to ensure the selected page is the page containing the TextBox. That fixes odd thing #2 and reduces two of the three messages when pressing Back to one.

The other is caused because the Back button is disabled during the page change. This seems to be moving focus back to the textbox right before the page is hidden. If you set Wizard.DisableButtonsDuringPageChange to false, that resolves that.

So then you're left with Odd thing #1, of which I can't figure out how to make it work like you would think that it would. I think it's just bad design on Microsoft's part. Please post if you find a workaround for that.


Actipro Software Support

Posted 18 years ago by Kasper
Avatar
Hi,

Wow, thank you for all the investigation. I'm sorry you had to go through so much trouble. I have removed the Validating event, and I'm now using the NextButtonClick event of the specific page, which actually seems to work just fine :)
Posted 18 years ago by Warren J. Hairston - President, Logical Operators, Inc.
Avatar
I'm having a similar problem. I have an interior page with several textboxes that are data-bound to a DataView object (I'm editing a record retrieved from a database).

If I type in a textbox and tab to the next field, then click the Next button - everything works as expected and the data in the DataView is updated with what I typed. However, if I type in a textbox, leave the cursor in the textbox (don't tab out), and click Next with the mouse, the data I've entered does NOT update the DataView through data binding (the original value is still in the DataView).

Is this related to the same issue as the original poster's problem?

Thanks in advance.
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm thinking so... it seems to just be bad implementation in the .NET framework by Microsoft. For some reason for validation at least, it requires that you tab through a control for it to be validated. Perhaps that's the same thing that is happening to you.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.