1

I need to count the rendering time of an UpdatePanel inside my page. Someone knows how to do that?

Thanks in Advance.

felipekm
  • 2,820
  • 5
  • 32
  • 42

2 Answers2

2

You could subscribe for the beginRequest and endRequest callbacks and calculate the elapsed time between them.

function pageLoad() {
    var manager = Sys.WebForms.PageRequestManager.getInstance();
    if (manager != null) {
        manager.add_beginRequest(Request_Begin);
        manager.add_endRequest(Request_End);
    }
}

function Request_Begin(sender, args)
{
    // TODO: start your timer here (new Date())
}

function Request_End(sender, args) {
    // TODO: get the current date and measure the difference
    // with theone obtained in the beginRequest
}

The following thread will help you in implementing the TODOs I left in my code.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Yeah thanks, but I'm still facing troubles with that one. The problem is the JS Date Calculate, as you said, I opened the another thread and tried to use the milliseconds format to calculate it, but without success. – felipekm Jul 18 '11 at 20:30
  • If is possible, could you please help me on this fiddle? http://jsfiddle.net/felipekm/gaZVH/ – felipekm Jul 18 '11 at 20:34
  • @FelipeKM, did you read the following thread: http://stackoverflow.com/questions/41948/how-do-i-get-the-difference-between-two-dates-in-javascript? – Darin Dimitrov Jul 18 '11 at 20:51
  • Yes I did, could you please read my fiddle? http://jsfiddle.net/felipekm/gaZVH/6/ – felipekm Jul 18 '11 at 20:59
  • @FelipeKM, yes, I opened your fiddle. There are errors with it. For example `alert(_dateDiff.);` is not valid javascript. – Darin Dimitrov Jul 18 '11 at 21:00
0

Firstly I'd like to thanks @Darin for all support, it was great! With the @darin suggestion I could make my target with some Math included such below:

    function get_time_difference(earlierDate, laterDate) {
    var nTotalDiff = laterDate.getTime() - earlierDate.getTime();
    var oDiff = new Object();

    oDiff.minutes = Math.floor(nTotalDiff / 1000 / 60);
    nTotalDiff -= oDiff.minutes * 1000 * 60;

    oDiff.seconds = Math.floor(nTotalDiff / 1000);
    oDiff.milliseconds = Math.floor(nTotalDiff * 1000);

    return oDiff;
}

var timeInit;
var timeFinal;

function pageLoad() {
    var manager = Sys.WebForms.PageRequestManager.getInstance();
    if (manager != null) {
        manager.add_beginRequest(Request_Begin);
        manager.add_endRequest(Request_End);
    }
}

function Request_Begin(sender, args) {
    timeInit = new Date();  
}

function Request_End(sender, args) {        
    timeFinal = new Date();
    var diff = get_time_difference(timeInit, timeFinal);
    alert('Minutes: ' + diff.minutes + '\nSeconds: ' + diff.seconds + '.' + diff.milliseconds);        
}

Hope this be useful for others devs. Thanks!

felipekm
  • 2,820
  • 5
  • 32
  • 42