locked
timer countdown problem (CRM 4.0) RRS feed

  • Question

  • Hi,

    i created in aspx a timer countdown which works on localhost. Now i integrated it like iframe on crm activities form ( task, email, ..).

    My timer don't work into crm. Here is :

    code behind:

    using

    System;


    using

    System.Collections.Generic;

    using

    System.Linq;

    using

    System.Web;


    using

    System.Web.UI;

    using

    System.Web.UI.WebControls;

    public

    partialclassChrono: System.Web.UI.Page


    staticDateTimeDateLancement;

       

    protectedvoidPage_Load(objectsender, EventArgse)

        {  

    if(!IsPostBack)

            {

    Timer1.Enabled =

    false;

                Timer1.Interval = 1000;

                TextBox1.Text =

    "00:00:00";

               

            }

        }

    protectedvoidTimer1_Tick(objectsender, EventArgse)

        {   

    DateTimeDateNow = DateTime.Now;

       

    // DateLancement = DateTime.Now;

    TimeSpanDifference = DateNow - DateLancement;

            TextBox1.Text = Difference.Hours.ToString(

    "d2") + ":"+ Difference.Minutes.ToString("d2") + ":";

            TextBox1.Text += Difference.Seconds.ToString(

    "d2");

          

        }

    protectedvoidDemarrage(objectsender, CommandEventArgse)

        { 

    switch(e.CommandName)

            {      

    case"Démarrer":

                    DateLancement =

    DateTime.Now;

                    Timer1.Enabled =

    true;

                 

                    ((

    Button)sender).Text = "Arrêter";

                    ((

    Button)sender).CommandName = "Arrêter";

               

    break;

               

    case"Arrêter":

                    Timer1.Enabled =

    false;

                    ((

    Button)sender).Text = "Démarrer";

                    ((

    Button)sender).CommandName = "Démarrer";

                   

    break;

             }

         }   

    }

    Friday, January 16, 2015 4:05 PM

Answers

  • i resolved this issue by using cookies on client side. just a simple html file with some script and change starttime(), incrementtimer()

    functioncreateCookie(name, value, days) {

               

    if(days) {

                   

    vardate = newDate();

                    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

                   

    varexpires = "; expires="+ date.toGMTString();

                }

               

    else


                   

    varexpires = "";

                document.cookie = name +

    "="+ value + expires + "; path=/";

            }

           

    functionreadCookie(name) {

               

    varnameEQ = name + "=";

               

    varca = document.cookie.split(';');

               

    for(vari = 0; i < ca.length; i++) {

                   

    varc = ca[i];

                   

    while(c.charAt(0) == ' ')

                        c = c.substring(1, c.length);

                   

    if(c.indexOf(nameEQ) == 0)

                       

    returnc.substring(nameEQ.length, c.length);

                }

               

    returnnull;

            }

    • Marked as answer by dc74 Tuesday, March 17, 2015 10:59 AM
    Tuesday, March 17, 2015 10:59 AM

All replies

  • Can you give more information. Do you get errors (if so, what is the error) ? How does it not work ?

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, January 16, 2015 9:10 PM
    Moderator
  • Hi

    thanks for reply, i changed method, and use a simple html file with some script. Now it's Ok. i just need to keep value af time even i make refresh or save. but now, it reset on refresh or reload.

    functionstartTimer() {

               

    // Update UI


                butStart.disabled =

    true;

              

    // butOk.disabled = false;


                butStop.disabled =

    false;

              

               

    //pas d'attente de seconde entière pour activer le tick


                incrementTimer();

               

    // Intervalle


                _iTimerId = window.setInterval(incrementTimer, 1000);

            }

    functionincrementTimer() {

               

    // Update the display


                updateDisplay();

               

    if(_iTimerSecondValue == 59) {

                    _iTimerSecondValue = 0;

                   

    if(_iTimerMinuteValue == 59) {

                        _iTimerMinuteValue = 0;

                        _iTimerHourValue++;

                    }

                   

    else{

                        _iTimerMinuteValue++;

                    }

                }

               

    else{

                   

    // Add a second


                    _iTimerSecondValue++;

                }

            }

    i had reset function and stop function. i was inspired by the code of Jim.


    • Edited by dc74 Wednesday, January 28, 2015 10:01 AM mistake when writing text
    Tuesday, January 27, 2015 2:08 PM
  • i resolved this issue by using cookies on client side. just a simple html file with some script and change starttime(), incrementtimer()

    functioncreateCookie(name, value, days) {

               

    if(days) {

                   

    vardate = newDate();

                    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

                   

    varexpires = "; expires="+ date.toGMTString();

                }

               

    else


                   

    varexpires = "";

                document.cookie = name +

    "="+ value + expires + "; path=/";

            }

           

    functionreadCookie(name) {

               

    varnameEQ = name + "=";

               

    varca = document.cookie.split(';');

               

    for(vari = 0; i < ca.length; i++) {

                   

    varc = ca[i];

                   

    while(c.charAt(0) == ' ')

                        c = c.substring(1, c.length);

                   

    if(c.indexOf(nameEQ) == 0)

                       

    returnc.substring(nameEQ.length, c.length);

                }

               

    returnnull;

            }

    • Marked as answer by dc74 Tuesday, March 17, 2015 10:59 AM
    Tuesday, March 17, 2015 10:59 AM