Last post Oct 21, 2009 02:51 AM by ps2goat
Oct 14, 2009 07:02 PM|ps2goat|LINK
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:
I assumed it was just a fluke because I have never run into this before. Any helpful insight into this would be appreciated.
Oct 15, 2009 01:39 PM|ps2goat|LINK
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.
Oct 20, 2009 05:21 PM|ps2goat|LINK
Any help is appreciated.
Oct 20, 2009 10:55 PM|Allen Chen – MSFT|LINK
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?
Oct 21, 2009 02:51 AM|ps2goat|LINK
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.