Javascript Problem on expand images
I have a problem with my TreeView here.
My TreeView is in a UserControl. On the first page, the UserControl is placed directly on the content page. Everything works finde.
example (working):
<a id="MainContent_CategoryTreeView1_TreeView1n209" href="javascript:TreeView_ToggleNode(MainContent_CategoryTreeView1_TreeView1_Data,209,MainContent_CategoryTreeView1_TreeView1n209,' ',MainContent_CategoryTreeView1_TreeView1n209Nodes)">
<img src="demo.jpg" />
</a>
On the second page, the UserControl is placed in a TabContainer (TabPanel). The javascript for expanding does not work.
What i found out is, that the ID of the table cell, the expand image is placed in, differs from the href where the javascript is in.
example (not working):
<a id="MainContent_TabContainer_tbPbl_Categories_CategoryTreeView1_TreeView1n209" href="javascript:TreeView_ToggleNode(MainContent_CategoryTreeView1_TreeView1_Data,209,MainContent_CategoryTreeView1_TreeView1n209,' ',MainContent_CategoryTreeView1_TreeView1n209Nodes)">
<img src="demo.jpg" />
</a>
Is that a bug of the ASP.Net TreeView? Any idea how to solve this?
EDIT:
May be interesting too: Whenever the TreeView is loaded first, i build the hierarchy in code and save the rootNode to the Cache. So, my Page Load event looks like:
if (CacheFacade.开发者_如何学CCategoryTreeView == null)
var rootNode = BuildHierachy();
CacheFacade.CategoryTreeView = rootNode;
//databind rootNode to TreeView
else
//databind from CacheFacade.CategoryTreeView
This is what messes the generated javascript up. But why? The javascript has the generated client ID's in it. Isn't that part of the rendering (after the PageLoad) ?
Ok i found out what the problem was here:
In this scenario, it is not possible to store the TreeNodeCollection (or the rootNode) in the Cache.
I thought, it was a clever idea to cache the whole collection to save the time for building the hierachy. But if i try to place the UserControl in another page (in another container), the generated expand/collapse javascript is messed up (Client IDs are not correct).
Well, for the future:
- Cache the data, the TreeView is build upon, yes !
- Cache the rootNode, no !
精彩评论