如何避免ContentPage中MasterPage的刷新
我有一个带有计时器的母版页,显示服务器时间并每秒刷新一次,在内容页面上我有一个使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了优化性能并减少往返次数,我建议您在页面启动时获取服务器上的时间。然后计算服务器和客户端时钟之间的差异。现在您可以使用 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,
您可以在 MasterPage 上公开计时器,然后访问它:
You can expose the timer on the MasterPage, and then access it: