Validating event

styxke

Member
Joined
May 18, 2006
Messages
16
Programming Experience
5-10
Hi all,

I have two textboxes on a form which have both a Validating event. One is derived from a commontextbox class which in turn has a validating event in the base class.

When I enter something in the textbox which isn't derived it does it's own validating but here I need to raise the validating event of the other textbox which in turn needs to raise the validating in the base class.

Any suggustions?

Thanks in advance.
 
You need to distinguish between RAISING events and HANDLING events. You don't RAISE an event in the derived class and the base class. There is only one object so there is only one event, and in fact the Validating event is raised in the Control class. Now, if you want to HANDLE that event using multiple methods then you can. You simply add additional variables to the Handles clause of the event handler. You might have one event handler that handles the event for just the derived class and another that handles it for both the base class and the derived class. Neither your base class nor your derived class know anything about any of these event handlers. That's the whole point of events: the object simply raises the event and then it's up to everyone is if and how they want to act when that event is raised.
 
Ok, but I don't think I was clear enough.

I want to raise a Validating event of a textbox when a user clicks a button for examlpe.

Thanks in advance.
 
You don't raise the Validating event of a control directly. The form has a Validate method that you can call to validate its controls. The usual thing to do is to call that method and validate the whole form. That validation process uses methods declared Friend internally so only the Framework can use them. This should be an indication that you are not intended to mess with this process. If you want to provide your classes with a method to validate them directly then you're going to have to call the OnValidating method internally to raise the event. I can't really see why you would want to validate any time other than when the user leaves the control or along with the rest of the form though, so the inbuilt validation mechanisms should be enough.
 
Back
Top