WithEvents oddness CslaDataSource and VB.Net

WithEvents oddness CslaDataSource and VB.Net

Old forum URL: forums.lhotka.net/forums/t/790.aspx


jas_nhs posted on Wednesday, August 02, 2006

    Whist an old hand at VB6 and more used to C#, I have an odd problem when using a number of CslaDataSources on a user contro, with the less-familiar VB.Netl. The "select" event handler is created in the predictable way:

  Protected Sub CslaDSUserAdmin_SelectObject(ByVal sender As Object, ByVal e As Csla.Web.SelectObjectArgs) Handles CslaDSUserAdmin.SelectObject
    e.BusinessObject = UserAccounts.GetUserAccounts()
  End Sub


but, on my home PC this throws a build error:

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

The ascx code is simply:
<cc1:CslaDataSource ID="CslaDSUserAdmin" runat="server" TypeAssemblyName="OSALib.SA.BusinessObjects"
  TypeName="OSALib.SA.BusinessObjects.UserAccount">
</cc1:CslaDataSource>

If I comment out the "handles..." bit, the above sub is not invoked (of course) and no records are read.
What to do???  I am using V2.0.3 of csla.dll (ref Assembly Version, in the file properties)
I'm wondering if this msg might be vaguely relevant: http://forums.lhotka.net/forums/post/2099.aspx

Many thanks for any guidance,

James.

xal replied on Wednesday, August 02, 2006

I'm not that much into web, but in windows forms (or just in a simple class), you need to do this:

Private WithEvents mInstanceName as SomeType

If for some reason you can't do that, you can do it as you would in c# with an addhandler in a constructor or in a load event, like:
AddHandler mInstanceName.EventName, AddressOf methodName


That way, you don't need to use the "Handles". To remove the handler the sintax is exactly the same except you use RemoveHandler.

Copyright (c) Marimer LLC