Results 1 to 5 of 5

Thread: Validating event

  1. #1
    styxke is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2006
    Posts
    16
    Reputation
    102

    Validating event

    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.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,748
    Reputation
    1618
    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.

  3. #3
    styxke is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2006
    Posts
    16
    Reputation
    102
    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.

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,748
    Reputation
    1618
    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.

  5. #5
    styxke is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2006
    Posts
    16
    Reputation
    102
    Ok, thanks for your input.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking