Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to generate page load time at server side in asp.net, C#.??????
I have tried with the below method but i don't want to use this....

C#
private int startTime;

protected void Page_Init(object sender, EventArgs e)
{
    startTime = Environment.TickCount;
}


C#
protected void Page_PreRender(object sender, EventArgs e)
{
    int endTime = Environment.TickCount;
    double executionTime = (double)(endTime - startTime) / 1000.0;

    lblLabel.Text = "Page Execution time is " + executionTime + " seconds.";
}
Posted
Updated 6-Feb-12 22:05pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Feb-12 4:05am    
"I'll generate Time and Space and gain Power over the World!" :-)
--SA
Sergey Alexandrovich Kryukov 7-Feb-12 4:06am    
How about using "Improve question" (above) to explain in detail what are you trying to achieve and what is the problem?
--SA
Aniket Yadav 7-Feb-12 4:09am    
It Seems You Need To Calculate The Total Time Required To Load The Page?

Is It Right?
rashmiverma 7-Feb-12 4:18am    
yes xactly on server side...
rashmiverma 7-Feb-12 4:42am    
Thanks....

1 solution

put
C#
int startCounter= DateTime.Now.TimeOfDay.TotalSeconds;
as a first statement in the page_load in order to to get the TotalSeconds when this application has been loaded

and at the end of the page load add
C#
int endCounter = DateTime.Now.TimeOfDay.TotalSeconds;


now add
C#
int totalSeconds = endCounter - startCounter;
//which will get the time needed to run this event.

C#
Response.Write(totalSeconds);


Also Refer This Link
http://msdn.microsoft.com/en-us/library/0x5wc973(v=vs.85).aspx[^]

Hope This Will Help You
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900