Code for Property in JobQuote class:
public class JobQuote
{
// Properties
private List<string> _jobfilenames;
public List<string> JobFileNames
{
get
{
if (_jobfilenames != null)
return _jobfilenames;
else
{
_jobfilenames = new List<string>();
return _jobfilenames;
}
}
set { _jobfilenames = value; }
}
Code for Property in User Control
public JobQuote quote
{
get
{
if (ViewState["Quote"] != null)
return (JobQuote)ViewState["Quote"];
else
{
JobQuote newQuote = new JobQuote();
return newQuote;
}
}
set { ViewState["Quote"] = value; }
}
Code in try block of UserControl where the string is not being added to the generic list of strings:
try
{
string filename = System.IO.Path.GetFileName(FileUploader.FileName);
quote.JobFileNames.Add(filename);
}
What am I doing wrong?
You are reading from the viewstate but you never assign.
This means that next time you refer to the quote property, a new JobQuote instance will be created rather than your old JobQuote instance being returned
A clean way for implementing this would be: