Results 1 to 5 of 5

Thread: Dynamic event handler stops working

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Dynamic event handler stops working

    I have a button on a form (within a panel) created in code. This button has an on-click event handler created with AddHandler attached to it and it works on the first click but not on subsequent clicks. There are 3 others buttons created in the same manner which always work. Any ideas? I tried doing Dim WithEvents and that didn't work.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,598

    Re: Dynamic event handler stops working

    Can you attach an example that shows the problem? Or at least post the code you're using.
    I stared as hard as I could, but can't really see clearly what you've done.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Dynamic event handler stops working

    Thanks for replying.
    Definition:
    Code:
    Dim LastButton As Button
    Creation:
    Code:
    LastButton = New Button
            LastButton.Width = 32
            LastButton.Height = 26
            LastButton.Top = 6
            LastButton.Left = 572
            LastButton.BackColor = Color.Khaki
            LastButton.Font = New Font("Courier New", 10, FontStyle.Bold)
            LastButton.Text = ">|"
            LastButton.Enabled = False
            AddHandler LastButton.Click, AddressOf LastButton_Click
            FooterPanel.Controls.Add(LastButton)
    Execution:
    Code:
        Private Sub LastButton_Click(ByVal Sender As System.Object, ByVal e As System.EventArgs)
            PagN = NPage
            DisplayPage(PagN, dt, PanelWidth)
        End Sub


    Quote Originally Posted by passel View Post
    Can you attach an example that shows the problem? Or at least post the code you're using.
    I stared as hard as I could, but can't really see clearly what you've done.

  4. #4
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Dynamic event handler stops working

    With events is only needed if you want to wire the handler at design time. Unless you have code that explicitly removes the handler somewhere, the handler should still be wired. Start by putting a break point in the handling routine and make sure it does indeed fire only once.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Dynamic event handler stops working

    I found the problem. Sometimes the execution is firing the page number textbox leave event. When I remove the page number textbox leave event it works fine. The page number textbox is set in the code. It's still strange tho because the firing of the textbox leave event appears to be delayed until a button is clicked. But it works if I take out this leave event code.

    My idea was to let the user simply tab out of page number after entering that field and it would process. But now I think I'll just require hitting the enter key (which is handled by the keypress event which is not fired in the code.)

    Thanks.

Posting Permissions

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



Click Here to Expand Forum to Full Width