1

I have a problem with the application state in Asp.net. I need a list of Strings that i would use in different forms in the same application. Here I add the list:

Application.Add("users", new List<String>());

In a new form I try to add a string to the list, but I get NullReferenceException in the second line of the code below.

 List<String> ls=(List<String>) Application.Get("users");
            ls.Add(TextBox4.Text);
Borut Flis
  • 15,715
  • 30
  • 92
  • 119

1 Answers1

3

In the first slot of code the string is empty because of {new List<String>()}. You need to add the string in the list. Only after that, call the Application variable in another form to avoid the NullReferenceException Exception.

manas
  • 397
  • 6
  • 25
Santosh
  • 44
  • 1