How to Count an UpdatePanel Progress?
I need to co开发者_开发技巧unt the rendering time of an UpdatePanel inside my page. Someone knows how to do that?
Thanks in Advance.
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.
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!
精彩评论