Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

VS 2010 Countdown Timer

$
0
0
Hi all,

I created a countdown clock reflecting the remaining time in hours, minutes and seconds on a page which is working well as far as the actual countdown goes. Unfortunately I found a problem: the moment the countdown clock is refreshed, i.e. each second, the process has an effect on other components of the page such as focus being lost from an input field and popup panels not performing the way they should.

Considering the above I went on the search for a solution and stumbled upon another, greater, concern: some experts claim the method I use places too much strain on the hosting platform and advise the use of a client-side java-script instead. So, before implementing the fix to the original problem, which involves replacing all other Panels with Update Panels, I’d appreciate your inputs whether the method being used is suitable or not. If not, please advise a proper solution?

Please consider the following:

ASP.Net:
Code:

<asp:UpdatePanel ID="upCountdown" runat="server" Visible="False" UpdateMode="Conditional">
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="tmrCountdown" EventName ="tick" />
                    </Triggers>
                    <ContentTemplate>
                        <div class="sidepanel">
                            <div class="sidepaneltitle03">Countdown Detail</div>
                            <div class="sidepanelcontent01">
                                <asp:Timer ID="tmrCountdown" runat="server" Enabled="False" Interval="1000"></asp:Timer>
                                <br />
                                <br />
                                <asp:Label ID="lblCountdown" runat="server" Font-Names="Tahoma" Font-Size="16px" Font-Bold="True" ForeColor="#D9251D" Height="25px"></asp:Label>
                                <br />
                                <asp:Label ID="lblCountdownnMessage" runat="server" Font-Names="Tahoma" Font-Size="11px"></asp:Label>
                                <br />
                            </div>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>

VB.Net:
Code:

    Protected Sub tmrCountdown_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles tmrCountdown.Tick

        If Session("TempHH") = 0 And Session("TempMM") = 0 And Session("TempSS") = 0 Then tmrCountdown.Enabled = False : Exit Sub
        If Session("TempMM") = 0 Then Session("TempHH") -= 1 : Session("TempMM") = 60
        If Session("TempSS") = 0 Then Session("TempMM") -= 1 : Session("TempSS") = 60
        Session("TempSS") = Session("TempSS") - 1
        lblCountdown.Text = Format(Session("TempHH"), "00") & ":" & Format(Session("TempMM"), "00") & ":" & Format(Session("TempSS"), "00")

    End Sub

Thanks in advance!

Viewing all articles
Browse latest Browse all 42220

Trending Articles