Question

I'm not so familiar with javascript, but I believe that there's a javascript timer that would be set to an asp label.

I managed to this timer in asp. below is my code.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <table>
                    <tr>
                        <td class="timer_display">
                            <asp:Literal ID="litTime" runat="server" Text="00:00:00">
                              </asp:Literal>
                        </td>
                    </tr>
                    <tr>
                        <td style="background:white;">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td style="background: white;">
                            <asp:Button ID="btnStart" runat="server" Text="Start"
                               CssClass="button" onclick="btnStart_Click" />
                        </td>
                    </tr>
                </table>
                <asp:Timer ID="tmrWatch" runat="server" Enabled="false" Interval="1000" 
                    ontick="tmrWatch_Tick">
                </asp:Timer>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="tmrWatch" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>

My problem with this code is it generates a large amount of log file as my administrator told me.

So I was thinking to replace it with a javascript timer.

my goal is to have a javascript timer that will trigger my asp literal.

Était-ce utile?

La solution

You need something like this:

<!DOCTYPE html>
<html>
<body>

<p>A script on this page starts this clock:</p>
<p id="demo"></p>
<button onclick="myStopFunction()">Stop time</button>

<script>
var myVar=setInterval(function(){myTimer()},1000);
function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}
function myStopFunction()
{
clearInterval(myVar);
}
</script>

</body>
</html>

Now instead of

you will use asp:literal and it's id will be demo as in the example. So it should work f9.

You can also follow this link:

http://forum.codecall.net/topic/51639-how-to-create-a-countdown-timer-in-javascript/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top