Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 3-Jan-13 18:39pm
v2
Comments
Sandeep Mewara 4-Jan-13 0:45am    
Per user wise or application wide?

created a table in database named " hit "
then
code on Page Load
VB
<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>
 
Share this answer
 
You can store a value in the Application object, or in a data store ( database, XML file, text file, etc ) to make it persist.
 
Share this answer
 
Comments
Sandeep Mewara 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 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)



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