C
C#2y ago
mrVinicius

❔ event handler not being triggered

I'm having difficulty making this event works, can someone more experienced point me what im doing wrong? I have a user control that has a button, and when i click this button i want my form to do something, but when i click the button it does not reach the method in the form.
8 Replies
mrVinicius
mrViniciusOP2y ago
Anchy
Anchy2y ago
if this is winforms then typically you would use the designer to register your events so that the designer can auto generate the event handler for you
JakenVeina
JakenVeina2y ago
yeah, the onClick() method? where are you attaching that to the button?
jcotton42
jcotton422y ago
onClick is actually registering the handler Rather odd
JakenVeina
JakenVeina2y ago
oh, derp that's what I get for assuming conventions yeah, that's very much not what "OnXXX" conventionally means so, from that snippet, everything appears to be in order what is the specific problem? Console.WriteLine("Button clicked"); should be running, no problem if it's really not, I'm going to have to say that saveBtn isn't the button you're clicking
mrVinicius
mrViniciusOP2y ago
Console.WriteLine("Button clicked") is being triggered, but the problem is the whole event is not being triggered. When i click the saveBtn, it has should trigger a event that RegisterUC_SaveBtn_Clicked is listening to, and when this happen a message should be displayed on screen. My initial idea was having a button on User Control that when clicked triggered a method in Form via events. I couldn't make it work and i have a deadline by tomorrow so i changed my approach to work with tabs, thus not needing to pass data around. Oddly enough i managed to make the events work between Form and Presenter layer, but not between Form and User Control, thanks anyway.
JakenVeina
JakenVeina2y ago
if Console.WriteLine("Button clicked"); is running, SaveBtn_Clicked is being triggered if RegisterUC_SaveBtn_Clicked is not running, then it's not listening to SaveBtn_Clicked
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server