TreeView inside UserControl not firing SelectedNodeChanged event RRS feed

  • Question

  • User1439367969 posted

    I have a TreeView inside a UserControl which is not firing the SelectedNodeChanged event. I'm using change set 9278 of the CSS Adapters compiled as a separate assembly. From a quick debug of the issue it seems that the problem surfaces on the line 69 of TreeViewAdapter:

    if (treeView != null)
    Visual Studio 2008 tells me that treeView is null at this point. This results in the appropriate event not being fired. Unfortunately my understanding of control adapters and time available to this problem limits me from being able to try and resolve this problem myself so any help would be greatly appreciated.
    Thursday, April 17, 2008 5:44 PM

All replies

  • User-1385398420 posted

    Can you report what is being reported for the Control property one line above (line 68):

                TreeView treeView = Control as TreeView;

    Friday, April 18, 2008 1:00 PM
  • User1439367969 posted

    The control I was working on has since been greatly changed, leading me to be unable to repeat that specific bug. However I am still seeing the issue.

    I've created a simple website (VS2008, Targeting .net 3.5), added the CSSFriendly dll and browser file. To the default page I've added a user control. The user control contains a simple TreeView within a Panel (for the purpose of this bug the panel is just a container). The TreeView has a OnAdaptedSelectedNodeChanged event which updates a label with the current time. This does not work as expected. My guess at this point is that the WebControlAdapterExtender.RaiseAdaptedEvent method doesn't not support user controls which contain a heirachy of elements.

    In order to prove this theory I added a quickly hashed together bit of code to the RaiseAdapterEvent method: 

    1    MethodInfo method = methodOwner.GetType().GetMethod(delegateName);
    2    if (method == null)
    3    {
    4    	Control parentUserControl = FindParentUserControl(AdaptedControl.Parent);
    5    	if (parentUserControl != null)
    6    	{
    7    		methodOwner = parentUserControl;
    8    		method = methodOwner.GetType().GetMethod(delegateName);
    9    	}
    10   }
    11   if (method == null)

    Lines 1 and 11 in the above snippet are pre-existing. I also added the following method: 

    1    private Control FindParentUserControl(Control control)
    2    {
    3    	if (control.Parent == null)
    4    		return null;
    5    	if (control.Parent is UserControl)
    6    		return control.Parent;
    7    	return FindParentUserControl(control.Parent);
    8    }

    Everything started to work as expected, including my original solution.

    It would be great to see a more suitable fix in the next change set.

    Sunday, April 20, 2008 12:54 PM