hygor Posted August 25, 2004 Posted August 25, 2004 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 Quote
Administrators PlausiblyDamp Posted August 25, 2004 Administrators Posted August 25, 2004 You would need to store the counter as either a session variable or an application variable. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hygor Posted August 25, 2004 Author Posted August 25, 2004 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 Quote
Administrators PlausiblyDamp Posted August 25, 2004 Administrators Posted August 25, 2004 Something like Dim Counter As Integer Counter = CType(Session("Count"), Integer) Counter = Counter + 1 Label2.Text = Counter.ToString Session("Count") = Counter Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hygor Posted August 25, 2004 Author Posted August 25, 2004 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! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.