Adding Handlers to Dynamic Objects

Results 1 to 2 of 2

Thread: Adding Handlers to Dynamic Objects

  1. #1
    Join Date
    Dec 1969

    Default Adding Handlers to Dynamic Objects

    Hi,<BR><BR>Can someone tell me what&#039;s wrong with the code below?<BR><BR>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> &#039;Put user code to initialize the page here<BR> &#039;various code to create and fill dataset<BR> For Each dr In objDS.Tables("main").Rows<BR> Dim myButton = New Button()<BR> Dim spacer = New System.Web.UI.LiteralControl()<BR> myButton.Text = dr.Item("name")<BR> myButton.ID = dr.Item("id")<BR> spacer.Text = "&#060;p&#062;"<BR> Form1.Controls.Add(spacer)<BR> Form1.Controls.Add(myButton)<BR> AddHandler myButton.Click, New EventHandler(AddressOf obj_Click)<BR> Next<BR><BR>Protected Sub obj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)<BR> Dim sButton As String = CType(sender, Button).ID<BR> Label1.Text = "The Button " & sButton & "was clicked."<BR> End Sub<BR><BR>VS chokes on the "myButton.Click" part of theAddHandler command .. it says click isn&#039;t an event associated with "system.object" ... yet myButton is clearly a button and not an anonymous object.<BR>Cheers,<BR>Matt

  2. #2

    Default RE: Adding Handlers to Dynamic Objects<BR><BR>Looks like it should only be AddressOf, now NEw EventHandler

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts