ASP.Net C# - Display Stopwatch -


i have page (page.aspx) includes stopwatch functionality time how long user spends on page on number of post backs shown below.

however, invisible user. how display on page stopwatch , each incremental second until stops?

protected void page_load(object sender, eventargs e) {     sw = new stopwatch();     sw.start(); }  protected void btnnext_click(object sender, eventargs e) {     //if not @ end of counter     {          //code     }     else     {         sw.stop();     } } 

try this:

.aspx page

<form id="form1" runat="server">     <asp:scriptmanager id="scriptmanager1" runat="server">     </asp:scriptmanager>     <asp:updatepanel id="updatepanel1" runat="server">         <contenttemplate>             <asp:label id="label1" runat="server" font-size="xx-large"></asp:label>             <asp:timer id="tm1" interval="1000" runat="server" ontick="tm1_tick" />             <div>                 <asp:button id="button1" text="next" onclick="button1_onclick" runat="server" />             </div>         </contenttemplate>         <triggers>             <asp:asyncpostbacktrigger controlid="tm1" eventname="tick" />         </triggers>     </asp:updatepanel>     </form> 

server side code:

 public static stopwatch sw;  protected void page_load(object sender, eventargs e) {     if (!ispostback)     {         sw = new stopwatch();         sw.start();     } } protected void button1_onclick(object sender, eventargs e) {     } protected void tm1_tick(object sender, eventargs e) {     long sec = sw.elapsed.seconds;     long min = sw.elapsed.minutes;      if (min < 60)     {         if (min < 10)             label1.text = "0" + min;         else             label1.text = min.tostring();          label1.text += " : ";          if (sec < 10)             label1.text += "0" + sec;         else             label1.text += sec.tostring();     }     else     {         sw.stop();         response.redirect("timeout.aspx");     } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -