FieldInfo.SetValue() and event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kernell
    New Member
    • Aug 2006
    • 1

    #1

    FieldInfo.SetValue() and event

    Hi everyone,

    i'm trying to initialize all control of a UserControl to is appropriate class. The value is set but the event won't raise anymore. See the example:

    Code:
    'Not working
    'Normally WithEvents should raise the event but nothing happen
    Public Class Process
            Inherits SkinProcess
    
            <SkinControlAttribute()> _
            Public WithEvents m_menu As RadMenu = Nothing
    
            Public Sub New()
                MyBase.new()
            End Sub
    
            Protected Overrides Sub InitializeSkin(ByVal skin As System.Web.UI.Control)
             
               'Parse each field to initialize m_menu
                For Each fInfo As Reflection.FieldInfo In Me.GetType.GetFields(BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.Static Or BindingFlags.NonPublic Or BindingFlags.DeclaredOnly)
                    Dim attributes As Object() = fInfo.GetCustomAttributes(GetType(SkinControlAttribute), True)
                    If attributes.Length > 0 Then
                        Dim skinAttribute As SkinControlAttribute = CType(attributes(0), SkinControlAttribute)
                        Dim controlID As String = fInfo.Name.Substring(1)
                        Dim ctlFoundControl As UI.Control = skin.FindControl(controlID)
    
                        If Not skinAttribute.IsOptional Then
                            If ctlFoundControl Is Nothing Then
                                Throw New GenericException("Could not find " + controlID + " in skin!")
                            End If
                        End If
    
                        'The value is set properly
                        fInfo.SetValue(Me, ctlFoundControl)
    
                    End If
                Next
    
            End Sub
    
            'Never Raised
            Private Sub m_menu_ItemClick(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) handles m_menu.ItemClick
                MakeAction(e.Item)
            End Sub
    End Class
    
    
    'Working, the event is raised
    Public Class Process
            Inherits SkinProcess
    
            <SkinControlAttribute()> _
            Public m_menu As RadMenu = Nothing
    
            Public Sub New()
                MyBase.new()
            End Sub
    
            Protected Overrides Sub InitializeSkin(ByVal skin As System.Web.UI.Control)
    
                        m_menu = skin.FindControl("m_menu")
    /***************
    OR
    
      For Each fInfo As Reflection.FieldInfo In Me.GetType.GetFields(BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.Static Or BindingFlags.NonPublic Or BindingFlags.DeclaredOnly)
                    Dim attributes As Object() = fInfo.GetCustomAttributes(GetType(SkinControlAttribute), True)
                    If attributes.Length > 0 Then
                        Dim skinAttribute As SkinControlAttribute = CType(attributes(0), SkinControlAttribute)
                        Dim controlID As String = fInfo.Name.Substring(1)
                        Dim ctlFoundControl As UI.Control = skin.FindControl(controlID)
    
                        If Not skinAttribute.IsOptional Then
                            If ctlFoundControl Is Nothing Then
                                Throw New GenericException("Could not find " + controlID + " in skin!")
                            End If
                        End If
    
                        fInfo.SetValue(Me, ctlFoundControl)
    
                    End If
                Next
              
                addhanler m_menu.ItemClick, adddressof m_menu_ItemClick
    
    *****/
            End Sub
    
            Private Sub m_menu_ItemClick(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) handles m_menu.ItemClick
                MakeAction(e.Item)
            End Sub
    End Class

    But the matter with the working code, i need to inialize each control. So if anyone knows why i can do FieldInfo.SetVa lue but the withevents don't work anymore

    Thanx a lot !!
Working...