Search code examples
c#listvariablespage-lifecycle

List is being emptied in the middle of a method


this has me puzzled - I am no expert on page life cycle but I do not see why this is happening. It may be a simple case of where I declare my list. Here is the code:

public partial class feedback : System.Web.UI.Page
{
    List<Module> allModules = new List<Module>();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            allModules = getAllModules();

            // Populate dropdown list of modules
            populateModulesDropDown();
...

The logic is this: the List 'allModules' get populated with Objects of a class called 'Module' in the getAllMethods() method. I have debugged and stepped through it testing on each step. allModules has a count of 9 as it should but when i step to the next line to run the populateModulesDropDown() method - the count is zero.. What is going on??

Any help would be awesome - thanks

Frank


Solution

  • I was returning a different List object from getAllModules() due to an overlooked line when making changes earlier. Apologies and thanks