By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,994 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,994 IT Pros & Developers. It's quick & easy.

Finding out the time user takes before hitting submit

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 26 Apr 2004 16:36:32 -0700, as*******@hotmail.com (Asad) wrote:
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.

Nov 18 '05 #2

P: n/a
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

"Asad" <as*******@hotmail.com> wrote in message
news:fd**************************@posting.google.c om...
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


Nov 18 '05 #3

P: n/a
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.

"Asad" <as*******@hotmail.com> wrote in message
news:fd**************************@posting.google.c om...
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

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.