incrementing a count

hygor

Newcomer
Joined
Aug 19, 2004
Messages
9
Location
Manchester, UK
I am trying to help a mate with his asp project he is trying to get a counter to update everytime you click the next button, i have set up a simplified version of his webform on my system... he is accessign a database record for the value of the count... that bit of his form works.. so i have left it off my mock up of his form... however when you click the button that updates the counter, the counter seems to reset as if the whole page is loading agian... the whole point of it is so that the page dynamically loads from a db.

here is the shortened code:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here


End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Dim Counter As Integer


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Counter = Counter + 1
Label2.Text = Counter
End Sub


End Class

if anyone knows a way to get the count to stick then that would be great!

Cheers!
Hygor
 
I actually know nothing about ASP (as it is not my project)

what does that mean exactly and could you show me a sample code or something?

Thanks very much
 
Something like
Visual Basic:
Dim Counter As Integer
Counter = CType(Session("Count"), Integer)
Counter = Counter + 1
Label2.Text = Counter.ToString
Session("Count") = Counter
 
Thanks mate, it worked a treat on my test page:D
am getting my mate to implement it now

once again you have been most helpful, ta very much!
 
Back
Top