|
-
May 6th, 2016, 09:24 AM
#1
Thread Starter
Fanatic Member
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.
-
May 6th, 2016, 09:34 AM
#2
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.
-
May 6th, 2016, 10:07 AM
#3
Thread Starter
Fanatic Member
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
 Originally Posted by passel
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.
-
May 6th, 2016, 11:51 AM
#4
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
-
May 6th, 2016, 08:37 PM
#5
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|