如何从工作线程更新页面

发布于 2024-09-11 19:28:35 字数 372 浏览 1 评论 0原文

我有一个从数据库查询的 ASPX 页面。一旦我们有了数据集,它就会绑定到网格视图并显示在页面上。所有这些都发生在 Page_Load 事件中。

当然,这是一种简单化的方法。通知用户正在检索数据以及何时我们有数据可以使用数据集中的结果更新页面的最佳方式是什么。

我希望所有这些都发生在同一个 ASPX 页面中,并且不想通过跳转页面来实现此目的。我查看了更新面板,但是我不清楚如何在没有触发更新面板更新的控件的情况下使用更新面板来完成此操作。我的页面上没有启动数据库查询的控件,它在页面加载时发生。

如果我在工作线程中执行查询,然后在包含 gridview 的 UpdatePanel 上调用 Update 方法,则它不起作用。什么也没发生。

有什么想法或帮助吗?谢谢。

I have a ASPX page which queries from a database. Once we have the dataset it is bound to a gridview and displayed on the page. All this happens in the Page_Load event.

Ofcourse this a simplistic approach. What is the best way to inform the user that data is being retrieved and when we have the data to update the page with the results in the dataset.

I want all this to happen within the same ASPX page and do not want to hop around pages to achieve this. I looked at update panels however it wasn't clear to me how this could be done with an update panel without having a control which triggers the update for the update panel. There are no controls on my page whhich initiate the database query, it occurs as the page is loaded.

If I do the query in a worker thread and then call the Update method on a UpdatePanel with the gridview as part of it, it doesn't work. Nothing happens.

Any thoughts or help? Thanks.

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

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

发布评论

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

评论(1

凉世弥音 2024-09-18 19:28:35

嗯,这是一个好问题。就我个人而言,我有两种非常相似的方法来执行此操作:

  1. 有一个 java 脚本,可以在短时间内重新加载 UpdatePanel。这将创建一系列到服务器的回发。在每次回发期间,您应该检查工作线程并立即返回状态报告,通常是错误待处理成功+数据之一
  2. 使用 Java 脚本向 Web 服务发出异步请求,该请求将阻塞直到获取数据。与前一种方法(轮询之间的时间)相比,此方法不会带来延迟,但可能会受到某些浏览器/服务器对挂起打开连接的态度的影响。这通常可以通过引入一些间隔(例如 1 分钟)来解决,以便挂起的请求将返回类似 need more time 的消息,在这种情况下,java 脚本应该简单地重复该请求。

Well, this is a good question. Personally I have two pretty similar methods to do this:

  1. Have a java script that will make an UpdatePanel reload with a short interval. This will create a series of post-backs to the server. During each post-back you should chek you worker thread and return immediately with the state report, usually one of error, pending, success + data
  2. With a java script, make an asynchronous request to a web-service that will block until the data is fetched. This method brings no latency as compared to the previous one (the time between polls), but may suffer from some browsers/servers attitude to hanging open connections. This is normally solved by some interval (say, 1 minute) introduced, so that the hanging request will return with a message like need more time, in which case the java script should simply repeat the request.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文