开发者

List is being emptied in the middle of a method

开发者 https://www.devze.com 2023-01-13 07:33 出处:网络
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:

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 dro开发者_运维技巧pdown 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


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消