回发前的 ASP.NET TreeView javascript

发布于 2024-07-11 12:22:45 字数 587 浏览 3 评论 0原文

我正在尝试使用 TreeViews 和 UpdatePanel 编写我认为相当常规的 AJAX 模式。 我的情况是这样的:

我在 UpdatePanel 中有一个 TreeView 。 我在另一个 UpdatePanel 中有一个文字。 当用户单击 TreeView 中的节点时,Literal 的内容就会更新。 现在,由于整个事情是异步的,因此单击和 Literal 内容的更新之间当然存在时间滞后。 在这段时间里,我想做两件事:

1)显示 UpdateProgress,

2)清除 Literal 的内容,

这样用户就不必在新文本出现时盯着旧内容异步加载。

我似乎无法找出完成(2)的简单方法。 我一直在阅读客户端回调并使用 GetCallbackEventReference,但这似乎是解决看似简单问题的非常复杂的方法。

理想情况下,我想让 TreeView 独自完成它的工作。 我不想自己获取内容并使用 JS 将它们添加到 TreeView 中。 我只想检测客户端的节点更改事件,清除 Literal,然后让 TreeView 继续其正常操作。

这可能吗? 或者客户回电是我唯一的选择吗?

I'm trying to code what I think is a fairly routine AJAX pattern using TreeViews and UpdatePanels. My situation is this:

I have a TreeView within an UpdatePanel. I have a Literal within another UpdatePanel. When the user clicks on a node within the TreeView, the contents of the Literal are updated. Now, since the whole thing is asynchronous, there is of course a time lag between the click and the update of the Literal contents. During this time, I'd like to do two things:

1) Show an UpdateProgress, and

2) Clear the contents of the Literal

This is so that the user doesn't have to stare at the old contents while the new text is getting loaded asynchronously.

I can't seem to figure out an easy way to accomplish (2). I've been reading up on client side callbacks and using GetCallbackEventReference, but it seems like a very complicated approach to what is seemingly a simple problem.

Ideally, I would like to leave TreeView alone to do it's work. I don't want to get the contents myself and add them to the TreeView using JS. I'd just like to detect the node change event at the client side, clear up the Literal, and let TreeView go about with its normal operation.

Is this possible? Or are client call backs my only option?

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

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

发布评论

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

评论(2

柠北森屋 2024-07-18 12:22:45

您将想要使用 ASP.NET AJAX 库中的 PageRequestManager。 以下是 PRM 的 MSDN 参考 - http://msdn.microsoft.com/ en-us/library/bb311028.aspx

请注意,微软已经声明 TreeView 在 UpdatePanel 中可能会出现问题,您还需要非常小心性能,特别是如果您有一个较大的 TreeView(请参阅我关于优化的文章) UpdatePanel 性能 - http://www.aaron-powell.com/blog。 aspx?id=1195)。 你真的应该看看像 jQuery 插件这样的东西(例如: http://bassistance. de/jquery-plugins/jquery-plugin-treeview/)。

但要真正回答您的问题,您需要:

  • 有一个 BeginRequest 事件处理程序,然后它将清除您的文字,甚至可以显示正在加载(我不喜欢 UpdateProgress,我更喜欢我自己做的更精细的控制)
  • 使用 EndRequest 事件来确保 Loading 组件消失

您还可以将 TreeView 设为页面上第二个 UpdatePanel 的 AsyncPostbackTrigger ,或者在 TreeView 的异步回发期间调用其 Update 方法

You'll be wanting to play with the PageRequestManager from the ASP.NET AJAX library. Here's the MSDN reference for the PRM - http://msdn.microsoft.com/en-us/library/bb311028.aspx.

Just be for warned Microsoft have stated that the TreeView can be problematic within the UpdatePanel and you'll also want to be very careful of the performance, particularly if you have a large TreeView (see my article on optimising the UpdatePanel performance - http://www.aaron-powell.com/blog.aspx?id=1195). You should really look at something like a jQuery plugin (eg: http://bassistance.de/jquery-plugins/jquery-plugin-treeview/).

But to actually answer you're question you need to:

  • Have a BeginRequest event handler which will then clear your literal and can even show a Loading (I'm not a fan of the UpdateProgress, I prefer much more granular control I get from doing it myself)
  • Use the EndRequest event to ensure that the Loading component vanises

You could also make the TreeView a AsyncPostbackTrigger of the 2nd UpdatePanel on the page, or just call the Update method on it during the async postback of the TreeView

迟到的我 2024-07-18 12:22:45

我遇到了同样的问题,并通过创建一个与我想要隐藏的区域重叠的隐藏 html 元素来修复它。 我在提交时显示它并在回发期间将其隐藏在 window.onload 中。 它并不漂亮,但它可以工作并且应该很快。

i had the same problem and fixed it by creating a hidden html element that overlaps the area i want to hide. I show it onSubmit and hide it in the window.onload during a postback. It's not pretty, but it works and should be fast.

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