如何避免ContentPage中MasterPage的刷新

发布于 2024-08-21 08:31:15 字数 269 浏览 3 评论 0原文

我有一个带有计时器的母版页,显示服务器时间并每秒刷新一次,在内容页面上我有一个使用ajax的聊天程序,每秒刷新一次以获取最后输入的消息。

我有一个 Html 文本框和一个隐藏的提交按钮,当用户编写文本并按 Enter 键时,我检查这是否是 Enter 键,然后提交消息,它在 IE 中工作正常,但在 FireFox 和 Opera 中工作正常它显示相同的消息两次。

我认为问题出在计时器上,有什么方法可以避免在这个特定内容页面中使用 MasterPage 计时器吗?

提前致谢

I have a masterpage with a timer that shows server time and refreshes every second, on the content page I have a chat program with ajax, refreshes every to second to get the last messages entered.

I have a Html TextBox and a hidden Submit Button, when user write a text, and hit the enter, I check to see if this is the enter key and then submit the message,it is working perfectly in IE, but in FireFox and Opera it show the same message twice.

I think the problem is the Timer, is there any way to avoid the MasterPage timer in this particular content page?

Thanks in advance

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

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

发布评论

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

评论(2

我要还你自由 2024-08-28 08:31:15

为了优化性能并减少往返次数,我建议您在页面启动时获取服务器上的时间。然后计算服务器和客户端时钟之间的差异。现在您可以使用 Javascript(仅限客户端,不再往返服务器)每秒更新屏幕上的时钟。

如果问题是由您提到的主题引起的,这也应该可以解决您的问题。无论如何,我认为您不必每秒请求服务器时间,这会给您自己和您的应用程序用户带来很大的好处。

希望这有帮助,

To optimize performance and reduce your roundtrips, i would like to suggest you get the time on the server once at start up of you page. Then calculate the difference between the server and client clock. Now you can use Javascript (Client side only, no more roundtrips to the server) to update your clock on your screen every second.

This should also solve your problem IF the issue is caused by the the topic you mentioned. Regardless, i think you´ll do yourself and your app users a great benefit by not requesting the server time every second.

Hope this helps,

身边 2024-08-28 08:31:15

您可以在 MasterPage 上公开计时器,然后访问它:

// On MasterPage
public Timer MyTimer { get { return this._myTimer; } }

// On Content Page
<%@ MasterType VirtualPath="~/MyMaster.master" %>

override OnLoad(EventArgs e) {
    base.OnLoad(e);
    this.Master.MyTimer.Enabled = false;
}

You can expose the timer on the MasterPage, and then access it:

// On MasterPage
public Timer MyTimer { get { return this._myTimer; } }

// On Content Page
<%@ MasterType VirtualPath="~/MyMaster.master" %>

override OnLoad(EventArgs e) {
    base.OnLoad(e);
    this.Master.MyTimer.Enabled = false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文