简体   繁体   English

UpdatePanel Asp.net C#中的计时器问题

[英]Timer issue in UpdatePanel Asp.net C#

i have an update panel with Timer, by defualt timer interval is 60 secs, I have 15 buttons on page, on each button click i want to assign timer interval 30 seconds, so each button click will give 30 seconds more until if not then timer_tick is called which will disable Timer and perform other works. 我有一个带有计时器的更新面板,默认计时器间隔为60秒,我在页面上有15个按钮,单击每个按钮时,我想将计时器间隔分配为30秒,因此,单击每个按钮都将多留30秒,直到不是,再加上timer_tick被称为将禁用定时器并执行其他工作。 Other buttons are not part of TimerUpdatePanel. 其他按钮不是TimerUpdatePanel的一部分。 On button clicks timer is not updating, Please Advise. 单击按钮时计时器未更新,请告知。 Thanks 谢谢

My Aspx Code: 我的Aspx代码:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<asp:Timer ID="Timer2" runat="server" Enabled="False" Interval="60000" OnTick="Timer2_Tick"></asp:Timer>
<asp:UpdatePanel runat="server" ID="updatePanelTimer2" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
    </Triggers>
    <ContentTemplate>
        <%--<p id="myTimer" runat="server" style="text-align: right; padding-right: 40px;"><%= Timer2.Interval.ToString() %></p>--%>
    </ContentTemplate>
</asp:UpdatePanel>

Code behind Button_Click Button_Click背后的代码

int timer = 30;
Timer2.Interval = timer * 1000;
updatePanelTimer2.Update();

Code of Timer_Tick Timer_Tick代码

protected void Timer2_Tick(object sender, EventArgs e)
{
    Timer2.Enabled = false;
    Session.Clear();
    Session.Timeout = 1;
    Session.RemoveAll();
    Session.Abandon();
    Response.Redirect("~/TestPage.aspx");
}

解决的问题:我只需要在ContentTemplate下添加<asp:Timer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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