locked
Event handler not being saved, vb.net 2008 RRS feed

  • Question

  • User955742345 posted

    FYI, I have a situation where I have a lot of nested user controls to better manage dynamic controls and I am about 4 user controls deep at this point.

    My problem is that I am adding the user controls dynamically, using Page.LoadControl, then dynamically adding event handlers using AddHandler ..., AddressOf ...

    I had 4 events wired and working as expected, but I added a new one today and it is not keeping its handler.  The events are all wired in a single location, so I do not understand why this new event does not retain its information.

    For example, I put a break point at the beginning of Page_Load and at the beginning of Page_PreRender for the user control that will not retain the event handler.  In Page_Load, after a Post back, all of the old events still have a method to execute as an event handler; the new event does not.  All events are handled by the same parent control, so why does the handler for the new event always show "Nothing" in the Watch window? 

    Things I tried:

    1. restarting the web server. 
    2. restarting Visual Studio 2008.
    3. Closing VS and deleting any remaining temporary files from the .NET directory.
    4. restarting my computer.

    I assumed it was just a fluke because I have never run into this before.  Any helpful insight into this would be appreciated.

    Wednesday, October 14, 2009 7:02 PM

All replies

  • User955742345 posted

    This is still an issue.  

    In order to get the new event handler working, I resorted to some pretty bad workarounds. 

    I create an Interface with a method to use as the event handler, then implemented that interface on the parent user control of the misbehaving user control.  I implmented the method of the Interface on the method I was previously using as the event handler.

    Next, I went to the location within the offending user control where I was trying to raise the event.  I did an If statement to see if the Event was nothing (had no event handler), and if so, I added an event handler and bound it to the naming container of the user control (which was the parent control). I had to cast the parent control to the Interface I mentioned above, and added the Interface method as the event handler.

    The Interface was needed because a circular reference exception won't let you compile if usercontrol A registers usercontrol B, then usercontrol B registers usercontrol A (for explicit type casting).

     

    I would still like to know if anyone is able to reproduce this or figure out why this is happening.

    Thursday, October 15, 2009 1:39 PM
  • User955742345 posted

    bump.

     

    Any help is appreciated. 

    Tuesday, October 20, 2009 5:21 PM
  • User-2106054853 posted

    Hi,

    I'm unable to repro this issue. Could you upload a demo that can reproduce this issue to http://skydrive.live.com/ and paste download link here for me to test? 

    Tuesday, October 20, 2009 10:55 PM
  • User955742345 posted

     I'll have to see.  It's a complicated system with a database, so I'll have to pare things back.  Chances are, once I do that the system will work.

    I'll let you know i I can get it to be reproducible with leaner code, and if so, post it to your mentioned site.

    Wednesday, October 21, 2009 2:51 AM