Time user takes before hitting submit

  • Thread starter Thread starter Asad
  • Start date Start date
A

Asad

Hi,

I was wondering how I can find out the time user takes on an aspx page
before hitting a submit button. Since there is that whole server-side
vs. client-side issue, I was thinking I can store the current time in
a variable on server side, and when the user hits submit, inside the
method invoked I take the difference of the time now and the
previously stored time.

It all makes sense right? And I'm new with ASP.NET coding, so I'd
appreciate if someone can show me a little bit of code so I know which
libraries to use and the syntax.

Thank you in advance.

Asad
 
On form_Load.....

If Not Page.IsPostBack Then

Session("CurrentTime") = DateTime.Now
Else
If Not Session("CurrentTime") is Nothing then

'Now you can subract CType(Session("CurrentTime", DateTime)) from
DateTime.Now to get your value. Use a Timespan or whatever date function
you want. DateTime.Now will give you the current time,
Session("CurrentTime") [use Ctype to cast it to a datetime] will give you
the value the page was loaded or refreshed but not if it was loaded via a
postback.
End If
End If
 
Back
Top