-1

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

braX
  • 11,506
  • 5
  • 20
  • 33
Frank
  • 1,110
  • 2
  • 16
  • 21
  • 1
    There is not enough information here to diagnose the problem. What I would do is try to *reduce* the problem. Start taking features out of your application until you have the *smallest possible* application that reproduces the problem. At that point either the problem will become obvious to you, or you will have something small enough that you can post all of it here. – Eric Lippert Aug 29 '10 at 14:30

3 Answers3

1

Well, the List is a field in your class, so other methods in the same class will have access to it. Perhaps some method is clearing it or assigning it ? Try to use the IDE to find all references of the field, and look for any assignments to the field.

driis
  • 161,458
  • 45
  • 265
  • 341
  • Thanks but the only method doing anything to it in this part of code is the getAllMethods() which does clear allMethods before it fetches them all and adds them to it.. Any ideas? – Frank Aug 29 '10 at 14:21
0

Because you are not calling populateModulesDropDown with either a parameter of allModules or not invoking the instance of allModules.populateModulesDropDown

Woot4Moo
  • 23,987
  • 16
  • 94
  • 151
  • populateModulesDropDown does not use a parameter of allModules. It simply references it as this.allModules. – Frank Aug 29 '10 at 14:19
  • Ok lets approach this logically. You populate allModules via a call to getAllModules. Then you make a call to a static function that knows nothing about allModules. This is why your list is 0 – Woot4Moo Aug 29 '10 at 14:28
  • Apologies I was returning a different list due to changing some code earlier and missing one line.. thanks for your help – Frank Aug 29 '10 at 14:52
  • agree. just try populateModulesDropDown(allModules). even if it doesn't work, you'll have improved your code ;) (it's kind of inconsistent that getAllModules() doesn't set the instance's field, but populate.. works with that field. avoiding such things helps avoiding problems like the one you're facing *even* if it turns out not to be the reason in this specific case) – Nicolas78 Aug 29 '10 at 14:53
0

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

Frank
  • 1,110
  • 2
  • 16
  • 21