views:

778

answers:

2

I have a treeview which i populate dynamically using an XML Datasource. The leaf nodes in the TreeView attempt to open a URL in an iframe within the page.

This all works fine, but i would like the iframe to be hidden until the point the leaf node is selected.

Does anyone know what event is triggered when the nodes are clicked?? I tried the SelectedNodeChanged event but this doesnt seem to get triggered!

Or is there any other way to do this??

UPDATE - The TreeView code is shown Below

<asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" DataSourceID="XmlDataSource2" AutoGenerateDataBindings="False">
  <DataBindings>
     <asp:TreeNodeBinding DataMember="Node"  NavigateUrlField="URL" ValueField="Name" TargetField="iframe" SelectAction="Select" />         
  </DataBindings>
</asp:TreeView>

While fiddling with my code i noticed that when i remove the NavigateUrlField="URL" from my code the tree triggers the SelectedNodeChange event, But does not Trigger if NavigateUrlField="URL" is put back in.

Any idea as to how i can get around this???

A: 

The AfterSelect event fires after the node selection has changed. The BeforeSelect right before the selection in the tree changes.

__grover
How do i use these?? as they arent available to me in the TreeView events?!
eMTeeN
Oh I'm sorry. I just now saw the ASP.NET 2.0 in the title. I thought you were asking for Windows Forms. However from reading the docs, the SelectedNodeChanged should be the right event.
__grover
+3  A: 

The SelectedNodeChanged is the correct event to trap in your scenario. Perhaps a little more detail might help to identify why this event is not raised.

Also, you should keep in mind that it is possible that the TreeView may not raise the event at all unless the SelectAction for the node is set to Select or SelectExpand. This might be a point to look into.

Edit: (after OP's update to original question):


This behaviour is quite natural. When you set the NavigateUrl of a TreeNode, it goes into "Navigation mode". This means that it renders as a hyperlink instead of a clickable node. Therefore, all selection events are disabled for such a TreeNode and the SelectedNode property of the TreeView will return a null reference. This is because the purpose of the TreeNode becomes solely the redirection to a supplied URL.

Now, there are a few solutions to solve this problem:

a. Instead of setting a NavigateUrl property declaratively, handle the SelectedNodeChanged event and set the IFrame's src attribute there conditionally depending on which node was clicked (the SelectedNode). Also set the IFrame's visibility to True.

b. Attach a client script to the onclick event of your TreeView within which you set the visibility of the IFrame. Examples on how to do this are on Madhur Ahuja's blog and here.

Hope this helps! :-)

Cerebrus
I have updated my question including the code. help would be appreceiated!
eMTeeN
Thanks!!! Your explanation does make sense! I guess I was trying to have the cake and eat it by wanting it to work both as a navigation tree and a clickable node :)
eMTeeN
You're most welcome and its my pleasure. Thanks for accepting the answer. :-)
Cerebrus