I have a global variable that I’m referencing in a ASP.NET web page update panel. Here’s what happens in the update panel:
accidentListType.Add(Convert.ToString(AccidentDescription.SelectedItem));
if (Atfault.Checked)
{
accidentAtFault.Add("True");
}
else accidentAtFault.Add("False");
DateTime newDate = new DateTime(Convert.ToInt32(accidentyear.Text), Convert.ToInt32(accidentmonth.Text), 1);
accidentListDate.Add(newDate);
TestAccidentLabel.Text = "Success! " + newDate.ToString();
Basically what happens is a list gets another added member every time a button is clicked. But every time it runs through the code, the new index mysteriously gets deleted, so when I go to add all of the accidents to the database, there’s no accidents to add. And I can’t add them dynamically, because one of the inputs to the accident database is the Identity from another table, which I pull when the table gets created, so I have to add them all after anyways.
Can anyone help?
P.S. This is my first time posting, so apologies if it’s messy or anything.
There are 2 things that you are missing. Though your list is Global, since after every request the page object is destroyed, until and unless you keep the list in Session, the values would not persist. Also, you have to reuse the list that you have kept in session for adding any new value. Do as following.