0

On page, I have UpdatePanel with Timer that works fine:

<asp:Content ID="content" ContentPlaceHolderID="contentholder" runat="server">
    <asp:ScriptManager runat="server" EnablePartialRendering="true"  ID="ScriptManager"></asp:ScriptManager>
    <asp:Timer ID="Timer" runat="server" Interval="10000" ></asp:Timer>
    <asp:UpdatePanel ID="MainUpdatePanel" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
<!-- some content, including repeaters... -->
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

I can't get event handler in code behind working though.

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        Timer.Tick += Timer_Tick;
    }
}

private void Timer_Tick(object sender, EventArgs e)
{
_someFlag = true;
}

I can see during debug that Timer.Tick += happens just fine, yet _someFlag never changes its value and _someFlag = true; never happens despite page itself updating correctly. What am I missing?

user2363676
  • 331
  • 2
  • 10

2 Answers2

1

You have to add OnTick="Timer_Tick" attribute to your timer:

<asp:Timer runat="server" id="Timer1" Interval="10000" OnTick="Timer_Tick"></asp:Timer>

And remove below code from Page_Load:

Timer.Tick += Timer_Tick;
0

Put 'Timer' inside 'Update panel' & 'Content Template' tag to handle trigger event