本文介绍了如何识别“计时器"的回调(“计时器在母版页中")内容页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面基于使用c#的asp.net中的主页和内容页面.
我在母版页中有一个计时器,如下所示:
my pages are base on master and content pages in asp.net with c#.
i have a timer in master page like below :
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer runat="server" ID="Timer1" Interval="10000" Enabled="False">
</asp:Timer>
<div id="SiteStatistics">
<asp:Label ID="lblDownload_Count_Title" runat="server" Text="Download Count :" ToolTip="Download Count :"
CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Count" runat="server" Text="<%# Download_Count() %>" CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Count_By_UserID_Title" runat="server" Text="Ur Download Count :"
ToolTip="Your Download Count From The Begining Of Registration UpTo Now" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Count_By_UserID" runat="server" Text="<%# Download_Count_By_UserID() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Count_By_UserID_Today_Title" runat="server" Text="Ur Download Count-Today :"
ToolTip="Your Download Count-Today" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Count_By_UserID_Today" runat="server" Text="<%# Download_Count_By_UserID_Today() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Size_By_UserID_Title" runat="server" Text="Ur Download Size :"
ToolTip="Your Download Size From The Begining Of Registration UpTo Now" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Size_By_UserID" runat="server" Text="<%# Download_Size_By_UserID() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Size_By_UserID_Today_Title" runat="server" Text="Ur Download Size-Today :"
ToolTip="Your Download Size-Today" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Size_By_UserID_Today" runat="server" Text="<%# Download_Size_By_UserID_Today() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Size_By_UserID_Today_Remain_Title" runat="server" Text="Ur Remain Download Size-Today :"
ToolTip="Your Remain Download Size-Today" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Size_By_UserID_Today_Remain" runat="server" Text="<%# Download_Size_By_UserID_Today_Remain() %>"
CssClass="lblCountInStatistics"></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>
此计时器每10秒滴答一次,并导致回调->由于该计时器,每10秒触发内容页面的第一page_load和母版页的最后page_load触发!
如何识别母版和内容页中的 timer'callback ,并防止由于回调而一次又一次地运行代码?
this timer ticks every 10 seconds and causes callbacks -> first page_load of content page and last page_load of master page fire every 10 seconds because of that timer!
how can i recognize that timer'callback in both master and content pages and prevent running codes again and again because of callback?
预先感谢
推荐答案
您有几种选择:
- 删除计时器.看来您实际上并不需要/不需要它.
- 在Master和Page的Page_Load上,将代码封装在
if(!IsPostBack){//code}
内 - 在Page_Load上检查
Request.Params["__EVENTTARGET"]
,并查看其中是否包含Timer1
- Remove the timer. It seems you don't actually want it/need it.
- on Page_Load of both, Master and Page, enclose your code inside a
if(!IsPostBack){//code}
- On Page_Load check
Request.Params["__EVENTTARGET"]
and see if it containsTimer1
这篇关于如何识别“计时器"的回调(“计时器在母版页中")内容页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!