Finding out the time user takes before hitting submit

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
 
D

Dan Brussee

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.

Your point of server / client side is good and would lead me to do the
timing on the client side. If you are testing how long a user is
looking at a page, it would be unfair to count the download and
tranfer times. Using Javascript, set a variable on pageload and on
submit, determine the time between now and the saved time. Pass that
value back to the server for processing and recording.
 
K

Ken Cox [Microsoft MVP]

Hi Asad,

If you want to do it on the server-side, you could set the time when the
page loads and store it in a viewstate. Then, when the postback happens (the
user clicked the button), you can calculate the time of the postback minus
the original time. All this is done in a TimeSpan.

Here's the idea:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
viewstate("starttime") = Now
Else
Dim tmspan As TimeSpan
tmspan = Date.Now.Subtract _
(CType(viewstate("starttime"), DateTime))
Label1.Text = tmspan.TotalSeconds.ToString
End If
End Sub

<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form>

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
D

Darren Clark

One way to do it in concept (code not sure)

have a hidden input box on the form.

on the onload event fire some javascript that updates this input box each
second.

then when the form is submitted you simply check the value in that box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top