takesoln Posted March 11, 2004 Posted March 11, 2004 Hi, I am drawing a textbox when a button is clicked. But, i want this to be done for the first time the user clicks on the button. My code is Private Sub Cash_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cash.Click Dim txtbox As New TextBox() txtbox.Width = Unit.Pixel(100) txtbox.Height = Unit.Pixel(20) PlaceHolder1.Controls.Add(txtbox) End Sub how do i track down the number of times the button has been clicked ? :o help me out ... Quote
georgepatotk Posted March 11, 2004 Posted March 11, 2004 Public TimeClicked as Integer Private Sub Cash_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cash.Click Dim txtbox As New TextBox() txtbox.Width = Unit.Pixel(100) txtbox.Height = Unit.Pixel(20) PlaceHolder1.Controls.Add(txtbox) TimeClicked = TimeClicked + 1 messagebox.show(TimeClicked) End Sub Quote George C.K. Low
takesoln Posted March 11, 2004 Author Posted March 11, 2004 This Does not work because, each time the page loads, the valiable will be initialized. I tried it with a session variable, but that doesn't work either ... can you suggest something so that the above mentioned textbox will not disappear after the page loads again ? Quote
georgepatotk Posted March 11, 2004 Posted March 11, 2004 i don't really get your idea. if you want to record down how many times the users had clicked on it and this record will still kept after restarting the program, you could either use text file, registry or a databases file.. is this what you want?? Quote George C.K. Low
georgepatotk Posted March 11, 2004 Posted March 11, 2004 Oh my god!! you are asking question based on ASP.net. sorry.. I thought it is in VB.NET. I am not really expert on it Thousand Apologizes Quote George C.K. Low
Administrators PlausiblyDamp Posted March 11, 2004 Administrators Posted March 11, 2004 Private Sub Cash_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cash.Click dim TimeClicked as integer TimeClicked=Session("ClickCount") Dim txtbox As New TextBox() txtbox.Width = Unit.Pixel(100) txtbox.Height = Unit.Pixel(20) PlaceHolder1.Controls.Add(txtbox) TimeClicked = TimeClicked + 1 Session("ClickCount")=TimeClicked messagebox.show(TimeClicked) 'This won't work in asp.net anyway though End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
dimple Posted March 11, 2004 Posted March 11, 2004 Hi, You can create a session variable in global.asax file and on button click can just increment that variable. And keep a check on the count. regards dimple Quote
takesoln Posted March 11, 2004 Author Posted March 11, 2004 I tried what you said plausiblydamp and Dimple... It works !! but, the textbox does not persist on some other event i.e. if the page loads again, the textbox disappears( Naturally .. because, the control does not exist ... so if i want to have the control after the page refreshes, what should i do ? hope you get my point ... Quote
Administrators PlausiblyDamp Posted March 11, 2004 Administrators Posted March 11, 2004 You would need to refer to the session variable in the relevant events (e.g. Page_Load) or alternatively you may want to investigate ViewState for controls. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
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.