简体   繁体   中英

how to avoid the Refresh in MasterPage in ContentPage

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

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,

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM