ASP.Net Ajax 可折叠扩展器 ViewState 问题

发布于 2024-07-29 22:41:58 字数 556 浏览 6 评论 0原文

我目前正在开发一个高级 Web 应用程序,其中包含许多动态渲染的页面。 这些页面是包含占位符的标准页面,其中主要内容是通过 Xml 和 Xslt 的组合呈现的。

我最近一直在尝试添加 ASP.Net Ajax Toolkit 可折叠扩展器,以允许动态呈现的面板折叠和扩展。 我已将扩展器标记添加到我们的主 xslt 模板中,一切都很好。 好吧,一切都很好,直到发生回发并且面板返回到其初始状态。 因此,例如,如果我加载面板折叠的页面,那么在回发后,页面无法重置任何打开的面板,问题是由于我将动态内容存储在视图状态本身中,并且一旦加载页面就导致了从视图状态检索它而不是重新呈现 Xml。

唷....这是问题的背景。

现在是主要问题。 你到底如何与 Javascript 中的扩展器交互。 我花了几天时间确信我可以将状态缓存在页面变量客户端中,然后重新应用状态回发。 然而,似乎没有关于如何实现这一点的文档或知识。 我发现的最好的是一些非常简单的 JavaScript,它允许您注册几个事件以在面板展开或折叠时捕获。

我想做的就是交互并缓存每个面板的状态。 任何人都可以提出任何建议吗?

I am currently working on an advanced web application that contains a number of Dynamically Rendered pages. The pages are standard pages which contain a place holder into which the main content is rendered from a combination of Xml and Xslt.

I have recently been attempting to add a ASP.Net Ajax Toolkit collapsible entender to allow the collapsing and extending of the panels which are dynamically rendered. I have added the extender markup to our main xslt template and all is fine. Well all is fine until a post back takes place and the panels return to their intial state. So, for example, if I load the page with the panels collapsed then after postback the page fails to reset any open panels, The problem is caused by the fact that I store the dynamic content in the viewstate itself and once the page is loaded just retrieve it from the viewstate rather than re-render the Xml.

Phew.... there is the background to the problem.

Now the main question. How on earth can you interact with the extender in Javascript. I have spent days convinced that I could cache the state in a page variable client side and then reapply the state post postback. However, there appears to be no documentation or knowledge of how to accomplish this. The best I have found is some very simple javascript which will allow you to register a couple of events to catch when the panel is extended or collapsed.

All I want to do is interact and cache each panels state. Can anyone suggest anything?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-08-05 22:41:58

好的,以防万一其他人需要实现类似的目标,我现在已经开始工作了。

经过大量研究,我发现您可以使用描述的任一方法连接到一些客户端事件 此处

因此,我决定最好的方法是以编程方式将几个隐藏字段 (ASP.Net HiddenField) 添加到 Page_Load() 事件中的页面,并将每个扩展程序的名称作为分隔字符串添加到一个字段中,然后为每个扩展程序添加一个字段扩展器保持扩展器状态。 一旦页面回发,就会从 Request.Form 对象中检索每个扩展程序隐藏字段的值(其键是隐藏字段 ID),否则如果是初始加载,则仅处理默认值。

然后,我创建了一个简单的客户端脚本,用于处理 onExpand 和 onCollapse 事件并更新特定扩展程序隐藏字段的值。

在客户端脚本的 pageLoad 事件中,我只是根据其隐藏字段值设置 enenders 状态。

真的很简单……一开始就应该这么想!

OK, Just in case anyone else needs to achieve similar I have now got it working.

After much research I found that you can hook up to a some client side events using either method described here.

So I decided the best way was to programtically add a couple of hidden fields (ASP.Net HiddenField) to the page in the Page_Load() event and add the names of each extender as a delimited string in one field and then have a field per extender to hold the extenders state. Once the page is posting back the value of each extenders hidden field is retrieved from the Request.Form object (the key of which is hidden fields ID) otherwise if it is the initial load just handle a default value.

Then I just created a simple client side script which handled the onExpand and onCollapse events and update the value of the specific extenders hidden field.

In the pageLoad event of the client script I just set the entenders state based on it's hidden fields value.

Simple really.... should have thought of it like that to start with!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文