简体   繁体   English

Javascript 展开图像时出现问题

[英]Javascript Problem on expand images

I have a problem with my TreeView here.我的 TreeView 有问题。

My TreeView is in a UserControl.我的 TreeView 在用户控件中。 On the first page, the UserControl is placed directly on the content page.在第一页上,UserControl 直接放在内容页上。 Everything works finde.一切正常。

example (working):示例(工作):

<a id="MainContent_CategoryTreeView1_TreeView1n209" href="javascript:TreeView_ToggleNode(MainContent_CategoryTreeView1_TreeView1_Data,209,MainContent_CategoryTreeView1_TreeView1n209,&#39; &#39;,MainContent_CategoryTreeView1_TreeView1n209Nodes)">
    <img src="demo.jpg" />
</a>

On the second page, the UserControl is placed in a TabContainer (TabPanel).在第二页上,UserControl 被放置在一个 TabContainer (TabPanel) 中。 The javascript for expanding does not work.用于扩展的 javascript 不起作用。

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.我发现,展开图像所在的表格单元格的 ID 与 javascript 所在的 href 不同。

example (not working):示例(不工作):

<a id="MainContent_TabContainer_tbPbl_Categories_CategoryTreeView1_TreeView1n209" href="javascript:TreeView_ToggleNode(MainContent_CategoryTreeView1_TreeView1_Data,209,MainContent_CategoryTreeView1_TreeView1n209,&#39; &#39;,MainContent_CategoryTreeView1_TreeView1n209Nodes)">
    <img src="demo.jpg" />
</a>

Is that a bug of the ASP.Net TreeView?这是 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.也可能很有趣:每当首先加载 TreeView 时,我都会在代码中构建层次结构并将 rootNode 保存到缓存中。 So, my Page Load event looks like:所以,我的页面加载事件看起来像:

if (CacheFacade.CategoryTreeView == null)
    var rootNode = BuildHierachy();
    CacheFacade.CategoryTreeView = rootNode;
    //databind rootNode to TreeView
else 
    //databind from CacheFacade.CategoryTreeView

This is what messes the generated javascript up.这就是将生成的 javascript 弄乱的原因。 But why?但为什么? The javascript has the generated client ID's in it. javascript 中包含生成的客户端 ID。 Isn't that part of the rendering (after the PageLoad)?这不是渲染的一部分(在 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.在这种情况下,不可能将 TreeNodeCollection(或 rootNode)存储在缓存中。

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).但是如果我尝试将 UserControl 放在另一个页面中(在另一个容器中),生成的展开/折叠 javascript 会搞砸(客户端 ID 不正确)。

Well, for the future:好吧,对于未来:

  • Cache the data, the TreeView is build upon, yes !缓存数据,TreeView 是在此基础上构建的,是的!
  • Cache the rootNode, no !缓存根节点,不!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM