.NET页面方法与UpdatePanel,哪个更适合更新刷新

发布于 2024-07-27 12:08:14 字数 298 浏览 2 评论 0原文

我还没有开始为这个程序编写任何代码,但这是我需要在 C#/ASP.NET 中执行的操作,这两者都是我刚刚开始学习的。

我在页面上有一个 DIV,我希望每五秒使用来自 MS SQL Server 的信息更新一次。

  1. 在 JavaScript 或 C# 端创建倒计时器会更好吗?

  2. 使用数据库信息更新 DIV 时,UpdatePanel 或创建页面方法会更有效吗?

    使用数据库信息

加载时间对于该应用程序来说是一个严重的问题,因此解决方案越轻、越快越好。

I haven't started writing any code for this program, but here's what I need to do in C#/ASP.NET, both of which I'm just starting to learn.

I have a DIV on a page that I want to update with information from an MS SQL Server every five seconds.

  1. Would it be better to create my countdown timer on the JavaScript or C# side?

  2. Would UpdatePanel or creating a Page Method be more efficient for updating the DIV with the database information?

Load times are a serious issue for this application, so the lighter and faster the solution, the better.

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

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

发布评论

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

评论(3

音盲 2024-08-03 12:08:14

1) 您必须在客户端上用 JavaScript 创建倒计时器,因为客户端与服务器端代码断开连接,除非它显式向其发送请求。

2) UpdatePanel 的效率会较低,因为它会发布页面的所有表单值(包括任何 ViewStateEventValidation 材料),当您可能需要传递给服务器的是几个字节(例如,对于 id)。 但是,如果查询时间较长(或者传输/呈现数据的成本较高),则这种效率差异可能并不显着。

1) You'll have to create the countdown timer on the client in javascript since the client is disconnected from your server-side code except when it explicitly sends requests to it.

2) UpdatePanel will be less efficient, because it posts all of your page's form values (including any ViewState or EventValidation material), when all you might need to pass to the server is a few bytes (for an id, for example). However, this difference in efficiency may not be significant if your query times are high (or the cost of transporting/rendering the data is high).

水水月牙 2024-08-03 12:08:14

UpdatePanel也会使用客户端的定时器来定期刷新。 因此,最好使用一些高效的 WebMethod,而不是使用 UpdatePanel 发送和检索整个表单值。 有关 UpdatePanel 和 WebMethods 优缺点的更多信息,您应该访问 Dave 的网站 (http://www.encosia.com)

The UpdatePanel will also use the timer on client side to refresh periodically. So it is better to use some efficient WebMethod rather than sending and retrieving whole form values using UpdatePanel. For more information regarding pros and cons of UpdatePanel and WebMethods you should visit Dave's website (http://www.encosia.com)

也只是曾经 2024-08-03 12:08:14

如果您决定使用 Web 服务,请改用 WCF。 ASMX 现在被 Microsoft 视为遗留技术。


对于怀疑者,请参阅“使用 ASP.NET 和 XML Web 服务客户端创建的 XML Web 服务”:

本主题特定于旧技术。 现在应使用 Windows Communication Foundation (WCF).


If you decide to use a web service, use WCF instead. ASMX is now considered legacy technology by Microsoft.


For skeptics, from "XML Web Services Created Using ASP.NET and XML Web Service Clients":

This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation (WCF).

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