468,512 Members | 1,428 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Constructor and RaiseEvent for validation

Hello

I am switching my courses from VB 6 to VB.Net. I teach my students to place validation inside the class. If data is invalid, then I want to raise an event in the form. This works fine when done from the Set property of a data member. I want to code a parameterized constructor so the user of the class can set initial values. I placed data validation in the constructor but it will not raise the event from the constructor. I tried creating a separate routine, say ValidateName and firing the event from there. This procedure works when it is called from the Set property. It does not work when it is called from the constructor.

If what I want to do is not possible, then what is the standard way of handling this? I teach my students not to use a messagebox or a form control inside the class because the class should be reusable. Also, I want to user of the class to handle invalid data as they see fit and raising an event solves that

Thanks in advance
Jani

Nov 20 '05 #1
1 2568
* "=?Utf-8?B?SmFuaXNLQg==?=" <an*******@discussions.microsoft.com> scripsit:
I am switching my courses from VB 6 to VB.Net. I teach my students to
place validation inside the class. If data is invalid, then I want to
raise an event in the form. This works fine when done from the Set
property of a data member. I want to code a parameterized constructor so
the user of the class can set initial values. I placed data validation
in the constructor but it will not raise the event from the constructor.
When the ctor code executes, event handlers are not already added.
If what I want to do is not possible, then what is the standard way of
handling this?


Throw an exception or something like that.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Nicolas | last post: by
2 posts views Thread by Carl tam | last post: by
2 posts views Thread by Lim | last post: by
2 posts views Thread by dmoonme | last post: by
7 posts views Thread by Onokiyo | last post: by
3 posts views Thread by Steven Blair | last post: by
1 post views Thread by Terry Olsen | last post: by
2 posts views Thread by ffa | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.