延迟加载 asp.net Ajax 控制工具包 手风琴
我正在使用 asp.net Ajax Control Toolkit 手风琴 (http://www.asp.net/ajaxlibrary/act_Accordion.ashx),每个手风琴窗格都包含相当多的信息。
所有这些信息都是在页面中生成的,但不会显示,因为工具包为非活动窗格提供了 a
(style="display:none;)
但因为信息位于页面中,所以它会成为一个需要加载的非常繁重的页面。
我正在寻找一种按需加载窗格的方法:因此,只有当用户单击窗格时,才会发送 ajax 请求,并且加载并展开窗格。
这可以用这个控件来完成还是我应该选择不同的手风琴?任何帮助或建议表示赞赏。
更新 目前,手风琴是用两个嵌套的中继器创建的。第一个中继器循环遍历类别并为每个类别创建一个面板。第二个重复器在每个面板内重复获取一个类别的内容并创建面板的内容。
普伦
I am using the asp.net Ajax Control Toolkit accordion (http://www.asp.net/ajaxlibrary/act_Accordion.ashx) and each accordion pane contains quite a lof information.
All that info is generated in the page but it is not shown because the toolkit gives the non active panes a
(style="display:none;)
But because the info is in the page, it becomes a very heavy page to load.
I am looking for a way to load the panes on-demand: so only if the user clicks the pane an ajax request is send and the pane is loaded and expanded.
Can this be done with this control or should i choose a different accordion? Any help or suggestions appreciated.
update
Currently the Accordion is created with two, nested, repeaters. The first repeater loops over the categories and creates a panel for each category. The second repeater repeates inside each panel takes the content for one category and creates the content of the panel.
Pleun
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有资格评论和问你问题。对不起。 :(
我的问题是关于您计划如何创建和填充手风琴。
您会使用 IDE 中的标记手动创建窗格,还是将 Accordion 绑定到将动态创建您需要的窗格的数据源?
您是否有 3 个独立的数据源或以下不同的组合:
1.) DataSource 用于初始化面板数量并仅填充面板的标题信息。
2.) 数据源在首次加载时填充所有面板的静态内容。
3.) 数据源填充用户单击展开的单个面板的延迟加载内容。
有了你的答案,我希望用真实的答案来更新这个答案。谢谢。
更新:这可以通过 Ajax Control Toolkit 的 Accordion 来实现。
下面有一些非常基本的代码作为概念证明。它可能会更流畅,但如果您认为有必要,我将让您自行使用 UpdatingProgress 控件添加“正在加载”图像。
Aspx 标记中的手风琴:
(注意 UpdatePanels - 如果需要,您可以用回调替换它们,我只是想让答案简单)
Page_Load() - 准备我们的“虚拟”数据:
ItemCommand() - 捕获 Accordion 内的按钮单击:
我知道这看起来很多,但它只是几行代码(在包装和注释之前)。
I don't have the points to comment and ask you questions. Sorry. :(
My questions are in regard to how you plan to create and populate the Accordion.
Will you create panes by hand using markup in the IDE or will you bind the Accordion to a DataSource that will dynamically create the panes you need?
Will you have 3 separate DataSources or a different combination of the following:
1.) DataSource to initialize the number of panels and populate only the panel's Header information.
2.) DataSource to populate the Static Content of all panels on first load.
3.) DataSource to populate the Lazy-Loaded Content of a single panel the user clicks to expand.
With your answers I hope to update this answer with a real one. Thanks.
Update: This is achievable with the Ajax Control Toolkit's Accordion.
I have some very basic code below as proof of concept. It could be smoother, but I'll leave it up to you to add a "Loading" image using the UpdatingProgress control if you find it necessary.
The Accordion in the Aspx markup:
(Notice the UpdatePanels - you can replace them with callbacks if you want, I just wanted to keep the answer simple)
The Page_Load() - Prep our "dummy" data:
The ItemCommand() - This captures button-clicks inside the Accordion:
I know this looks like a lot, but it's only a few lines of code (before wrapping and commenting).
使用 ASP.NET AJAX Accordion Control 的 6 个提示中的提示 4 解释了如何操作确定所选索引何时发生更改。从 JavaScript 事件处理程序中,您可以执行任何您想要的操作来更新新选择的折叠面板的内容(调用 Web 服务、使用更新面板等)。
将此与另一篇解释 当选择标签页进行简单操作时如何使用更新面板刷新内容演示:
然后在代码隐藏中
Tip 4 in 6 Tips for Working with the ASP.NET AJAX Accordion Control explains how to determine when the selected index has changed. From the JavaScript event handler you can do whatever you want to update the content of the newly-selected accordion pane (call a web service, use an update panel, etc.)
Combining this with another article explaining how to use an update panel to refesh content when a tab page is selected for a simple demo:
then in code-behind
看一下 ASPxNavBar 控件(免费 ASPxperience Suite 的一部分)来自DevExpress。如果 ASPxNavBar 的 EnableCallBacks 属性设置为 true,则折叠组的内容不会在客户端显示。当第一次展开某个组时,将从服务器检索其内容,然后缓存在客户端上。下次展开该组时,将从客户端获取其内容,并且不会执行对服务器的回调。
有关详细信息,请查看 ASPxNavBar - 回调 (AJAX) 在线演示。
Take a look at the ASPxNavBar control (a part of the free ASPxperience Suite) from DevExpress. If the ASPxNavBar’s EnableCallBacks property is set to true, contents of collapsed groups are not represented on the client side. When a group is expanded for the first time, its content is retrieved from the server and then cached on the client. The next time the group is expanded, its content is taken from the client and no callback to the server is performed.
Review the ASPxNavBar - Callbacks (AJAX) Online Demo for more information.
我可以建议您的是将 linkButtons 添加到标题,将面板添加到窗格:
并在
Accordion1_ItemCommand
中设置相应面板的Visible
属性。All I can suggest to you is add linkButtons to your headers and panels to your panes:
and in the
Accordion1_ItemCommand
set theVisible
property of corresponding panel.