Click here to Skip to main content
11,428,876 members (62,558 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
how to implement that on each time page is load the value is increased and displayed in label
e.g
on page load label-1 is displaying 1
and if page is loaded again then label-1 should display 2 and so on on ,each time the page load the value of label-1 should increase by 1 .
Posted 3-Jan-13 19:31pm
Edited 3-Jan-13 19:39pm
v2
Comments
Sandeep Mewara at 4-Jan-13 0:45am
   
Per user wise or application wide?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

created a table in database named " hit "
then
code on Page Load
<pre lang="vb">If Not IsPostBack Then
Dim co, jo As Integer
                cn.ConnectionString = &quot;server=localhost; user id=root; password=; database=**&quot;
                cn.Open()
                co = 1
                s = &quot;select * from hit where id=&#39;&quot; &amp; co &amp; &quot;&#39; &quot;
                cd = New MySqlCommand(s, cn)
                r = cd.ExecuteReader()
                r.Read()
                jo = CInt(r(&quot;count&quot;).ToString())
                Label5.Text = r(&quot;count&quot;).ToString()
                r.Close()
                cn.Close()
 
                Dim c As Integer
                Dim s1 As String
                cn.ConnectionString = &quot;server=localhost; user id=root; password=; database=**&quot;
                cn.Open()
                co = 1
                c = jo + 1
                s1 = &quot;update  hit set count=&#39;&quot; &amp; c &amp; &quot;&#39; where id=&#39;&quot; &amp; co &amp; &quot;&#39;&quot;
                cd = New MySqlCommand(s1, cn)
                cd.ExecuteNonQuery()
                cn.Close()
 End If
</pre>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can store a value in the Application object, or in a data store ( database, XML file, text file, etc ) to make it persist.
  Permalink  
Comments
Sandeep Mewara at 4-Jan-13 0:47am
   
Application object would force the counter across users. It should surely help if that is what OP seeks (But having a counter across users does not make any sense to me)
Christian Graus at 4-Jan-13 1:15am
   
Number of views makes sense to me. He can't have a counter per user unless the users have to log in.

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



Advertise | Privacy | Mobile
Web04 | 2.8.150428.2 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100