Silverlight novice needs help

Silverlight novice needs help

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


griff posted on Tuesday, August 31, 2010

Hi

Gone back to basics....two fields, one button...field accepts an ID, button goes and gets BO and populates field2. Using latest Codesmith templates (3.0).

here is my "Asynchronous Root Factory Method"

Public Shared Sub GetByProductIdAsync(ByVal productId As System.String, ByVal handler As EventHandler(Of DataPortalResult(Of Product)))

            Dim dp As New DataPortal(Of Product)()

            AddHandler dp.FetchCompleted, handler

            Dim criteria As New ProductCriteria()

            criteria.ProductId = productId

            dp.BeginFetch(criteria)

   End Sub

 

Button behind code is....

    Private Sub LoadData(ByVal ID As String)

        Dim bo As Business.Product = Business.Product.GetByProductIdAsync(ID,?????????? )

        ProdDesc.Content = bo.Description

    End Sub

I don't know what to put for the ???????? (it's expecting ByVal handler As EventHandler(Of DataPortalResult(Of Product))
Please can you help...
Richard

JonnyBee replied on Tuesday, August 31, 2010

Hi,

Basically - you need to supply the address of a sub to be called when the async Fetch is completed:

   Private Sub LoadData(ByVal ID As String)
        Business.Product.GetByProductIdAsync(ID, AddressOf FetchCompleted)
    End Sub

  Private Sub FetchCompleted(ByVal sender As Object, ByVal e As Csla.DataPortalResult(Of Product))
    If e.Error IsNot Nothing Then
     ' an execption occured - notify the user
    Else
      ProdDesc.Content = e.Object.Description
    End If
  End Sub

 

griff replied on Tuesday, August 31, 2010

Thanks Jonny, just managed to sort myself as well......it's good to know I was on the right lines...thankls once again

Copyright (c) Marimer LLC