Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Events and Delegates


Message #1 by "Bob Riley" <briley@c...> on Sun, 2 Mar 2003 00:40:34
I'm having a problem getting an event to fire in a usercontrol, which 
initiates a subroutine in the page where the usercontrol resides.  When I 
execute the page, I receive no errors, but I'm not getting the results I 
would expect.  What am I doing wrong? (I have omitted most excess code 
for breviaty)
  
<Code>
--Usercontrol (selectarea) codebehind
Public MustInherit Class SelectArea
Public Event MyEvent As MyEventDelegate
    Public Delegate Sub MyEventDelegate(ByVal sender As System.Object, 
ByVal e As System.EventArgs)
Sub btnSelectArea_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnSelectArea.Click
        Dim anItem As DataListItem
        Dim blnIsChecked As Boolean
        Dim intCheckedArea As Integer
        Dim colSelectedArea As ArrayList
        Dim chkSelected As System.Web.UI.WebControls.CheckBox
        colSelectedArea = New ArrayList()
        For Each anItem In dlstActiveAreas.Items
            chkSelected = anItem.FindControl("chkAreaChoice")
            If chkSelected.Checked Then
                intCheckedArea = dlstActiveAreas.DataKeys
(anItem.ItemIndex)
                colSelectedArea.Add(intCheckedArea)
            End If
        Next
        RaiseEvent MyEvent(Me, e)
 End Sub
End Class
---Page object (codebehind)
Public Class ViewAllBids
    Inherits System.Web.UI.Page
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
        Dim objMyUserControl As SelectArea
        objMyUserControl = CType(LoadControl
("UserControls/SelectArea.ascx"), SelectArea)
        AddHandler objMyUserControl.MyEvent, AddressOf ucSelectArea

    End Sub
    Private Sub ucSelectArea(ByVal sender As System.Object, ByVal e As 
System.EventArgs)
        lblMessage.Text = "btnSelectArea Clicked"
    End Sub
End Class
</Code>

I figure, if this were working properly, I would see "btnSelectArea 
Clicked" in the output on my webform.  
Can anyone see what I've done wrong?
 

  Return to Index