Raising Custom Events

Rick_Fla

Centurion
Joined
Nov 19, 2003
Messages
188
Location
Melbourne, Florida
Ok, my google skills have failed me. I try and search for the answer but keep getting caught on custom control event, which is not what I want. Here is what I am trying to do.

I have a Class Called SiteUsers. In the class I have an event declared as such:
Code:
Public Event BadData(ByVal PropertyName as string)

Inside the class I have a property

Code:
Public Property UserName() As String
        Get
            UserName = m_Username
        End Get
        Set(ByVal Value As String)
        m_UserName = value
        RaiseEvent BadData("UserName")

        End Set
    End Property

Just for a test I was raising the event no matter what, just to make sure things were happy.

On my Code behind File I Declare the object
Code:
Private WithEvents oSiteUser as SiteUser

In the load event the object is getting set with a new statement passing it some needed code.

To capture the BadData event, I have the following

Code:
Private Sub BadData (ByVal PropertyName as string) handles oSiteUser.BadData

'Some code

End Sub

I set a break point on the Sub and it never gets called. What am I missing here? I am new to the ASP.NEt world, so I am not sure what I could be missing, or if the postback stuff is screwing me up. Thanks for any pointers you can hand my way.
 
Try putting a breakpoint on the chunk of code where you are raising the event -- just to make sure it's firing.
 
Mister E - I have put break points on the code. The raiseevent code is firing, the event handler is not firing.

PlausiblyDamp - This is not a server control, it's a normal class object. What I am trying to do, and maybe I will just not go this route, is trying to put all the validation in the class and not on the page itself. So I am trying to use the event to notify the page that the data entered was bad data.

I am trying to go with the whole business layer idea, where all the logic is in the class, and not in the UI (being the webpage and code behind).

Thanks for the help though, I am not sure if I am explaining myself.
 
Back
Top