CollapsiblePanelExtender:我可以从客户端 JavaScript 启动折叠/展开吗? (AJAX控制工具包)
CollapsiblePanelExtender 似乎主要设计用于响应用户鼠标事件折叠/展开内容。 是否还有一种好方法可以让扩展器折叠/展开内容以响应客户端 JavaScript?
在我的特定情况下,我在页面上有许多 CollapsiblePanelExtender(及其相应的面板),我想知道是否可以通过严格在客户端执行类似的操作来实现“展开所有面板”按钮:
for each CollapsiblePanelExtender on this page, call somethingOrOther(extender)
我可以如果我进行了完整的回发,则在服务器端实现此逻辑,但我的页面需要很长时间才能加载,因此这似乎不会提供非常流畅的用户体验。 因此我对扩展/折叠客户端感兴趣。
看起来这不是 AJAX Control Toolkit 人们想到的用例,但我想我应该检查一下。
The CollapsiblePanelExtender seems primarily designed to collapse/expand things in response to user mouse events. Is there also a good way to get the extender to collapse/expand things in response to client-side javascript?
In my particular case, I have a number of CollapsiblePanelExtenders (and their corresponding Panels) on a page, and I'm wondering if I could implement an "expand all panels" button by doing something like this strictly on the client side:
for each CollapsiblePanelExtender on this page, call somethingOrOther(extender)
I can implement this logic server-side instead if I did a full postback, but my page takes a long time to load, and so this doesn't seem like it would provide a very slick user experience. Thus I am interested in doing expand/collapse client-side.
It seems like this isn't a use case the AJAX Control Toolkit people had in mind, but I thought I'd check.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Image/button 的 OnClick 事件中编写以下代码
希望这会有所帮助!
Write the following code in the OnClick event of Image/button
Hope this helps!
我现在有一个部分有效的解决方案。
我听从了 Ian 的建议并浏览了工具包源代码。 在
CollapsiblePanelBehavior.debug.js
中,您可以看到expandPanel()
显然是作为该行为的公共接口的一部分。 还有一个get_Collapsed()
。 在 javascript 中访问这些行为的关键似乎是在 ASP.NET 中的CollapsiblePanelExtender
标记上设置BehaviorID
属性。我修改了页面上的转发器,以便
BehaviorID
是可预测的,大致如下:这会产生名为
collapsebehavior1
、collapsebehavior2
、< code>collapsebehavior3 等。完成此操作后,我可以展开客户端上的所有可折叠面板,如下所示:
我确信在这样的循环中使用
$find
确实效率很低,但这就是我到目前为止所拥有的。此外,由于某种原因,它无法在 Firefox 上运行。 (在 FF 上,只有第一个元素展开,然后 Control Toolkit 代码中出现 Javascript 错误。)
对于所有 JavaScript 专家来说,这一切都显得极其丑陋。 也许我稍后会把事情清理干净,或者你可以帮我。
I have a partly working solution now.
I followed Ian's suggestion and looked through the toolkit source. In
CollapsiblePanelBehavior.debug.js
, you can thatexpandPanel()
is apparently intended as part of the public interface for the behavior. There's also aget_Collapsed()
. The key to accessing these behaviors in javascript seems to be setting theBehaviorID
property on yourCollapsiblePanelExtender
tags in ASP.NET.I modified the repeater on my page so that the
BehaviorID
s are predictible, along these lines:This results with behaviors named
collapsebehavior1
,collapsebehavior2
,collapsebehavior3
, etc..With this done, I'm able to expand all the collapsible panels on the client as follows:
I'm sure using
$find
in a loop like that is really inefficient, but that's what I have so far.Also, it doesn't work on Firefox for some reason. (On FF only the first element expands, and then there's a Javascript error inside the Control Toolkit code.)
This will all seem extremely ugly to all you javascript pros. Maybe I'll clean things up later, or you can help me out.
您还可以仅切换面板以在折叠/展开状态之间切换:
You can also just toggle the panels to switch between collapsed/expanded states: