I have a DotnetNuke control (using version 1 of DNN) where users enter visits to clients. They wanted a cumulative total as they are entering. They enter a variable number of visits per day - sometimes 3, sometimes 5, sometimes 6, etc. I made the form so it generates a set of controls as they are entering - so all the dropdowns, text boxes, are dynamically created as they need them. Everything works fine as far as the users selecting activity, client, visit duration, etc. I even have the cumulative total working, but only if a single user is entering data. When several users are entering data at the same time, the cumulative total shows all user's totals. I am posting my code, if someone can tell me where I've gone wrong, I'd really appreciate it. (Note: I tried declaring dblVisitTotal as a static variable in the text_changed code to hold the total, but it wouldn't collect the cumulative total for all the visit duration text boxes, I would only get the last duration entered, so I changed it to a Shared variable in the class. Is this the reason it's adding all user's totals when several are using it at the same time? I'm sure I've used static variables with success in the past, but not sure if it doesn't work because of the dynamic nature of the controls, etc. I'm sure I've made really stupid errors, any suggestions would be appreciated. I'm fairly new to all of this, so won't be offended at any suggestions)
Here is the code for the text_changed method for the control:
Private
Sub txtVisitDuration_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
If sender.GetType.ToString = "System.Web.UI.WebControls.TextBox" Then
Try
Dim ctl As New System.Web.UI.WebControls.TextBox
ctl = sender
If v13wstat3.Item(ctl.ID) Is Nothing Then
'add to view state, first time control has been populated
v13wstat3.Add(ctl.ID, ctl.Text)
'remove after testing
'Response.Write("Item " & ctl.ID & " created in View State.")
Else
'remove old value of text box, text has changed
dblActivityTotal -= Convert.ToDouble(v13wstat3.Item(ctl.ID))
'assign new value of text box
v13wstat3.Item(ctl.ID) = ctl.Text
'remove after testing
'Response.Write("Item value for " & ctl.ID & " changed in View State.")
End If
dblActivityTotal += Convert.ToDouble(v13wstat3.Item(ctl.ID))
txtCumTotal.Text = dblActivityTotal.ToString()
v13wstat3.Item("txtCumTotal") = dblActivityTotal.ToString()
'Response.Write("txtCumTotal v13wstat3 = " & v13wstat3.Item("txtCumTotal") & "<br>")
'Response.Write("<br>SubTotal: " & sngActivityTotal.ToString())
Catch ex As Exception
End Try
End If
End Sub
Thanks in advance for any suggestions/help/advice, I certainly need it!!!!
Miss P