Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. ArrayList on my Page

ArrayList on my Page

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 4700225
    wrote on last edited by
    #1

    I am creating this page where I am reading from the database using a SqlDataReader and Loading the info into an ArrayList. The ArrayList is a class member and the ArrayList object has been created in the class constructor, therefore, this object should be visible to all other members of the class. However, if I add some objects to the ArrayList in a MenuItem_Click and then try to read those added objects from a Button_Click, it shows the ArrayList is empty - which seems quite surprising. Obviously I am missing something. Any help? Thanks. Ekjon

    C 1 Reply Last reply
    0
    • M Member 4700225

      I am creating this page where I am reading from the database using a SqlDataReader and Loading the info into an ArrayList. The ArrayList is a class member and the ArrayList object has been created in the class constructor, therefore, this object should be visible to all other members of the class. However, if I add some objects to the ArrayList in a MenuItem_Click and then try to read those added objects from a Button_Click, it shows the ArrayList is empty - which seems quite surprising. Obviously I am missing something. Any help? Thanks. Ekjon

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The two clicks happen on different postbacks, so there's a new list each time.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      M 1 Reply Last reply
      0
      • C Christian Graus

        The two clicks happen on different postbacks, so there's a new list each time.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        M Offline
        M Offline
        Member 4700225
        wrote on last edited by
        #3

        Hi Christian, Thanks for the reply. I worked mostly with non-web-based apps, so I thought if I create the ArrayList in the costructor, its always the same List unless the page is disposed. So, what would be the solution? How do I get the same Even if I use a DataSet, is it gonna behave the same way? Please help. Thanks. Ekjon

        C 1 Reply Last reply
        0
        • M Member 4700225

          Hi Christian, Thanks for the reply. I worked mostly with non-web-based apps, so I thought if I create the ArrayList in the costructor, its always the same List unless the page is disposed. So, what would be the solution? How do I get the same Even if I use a DataSet, is it gonna behave the same way? Please help. Thanks. Ekjon

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Everything is going to work the same way, your options are: 1 - store it in viewstate ( this means it goes down to the client every time, making it insecure, and also making your pages huge ) 2 - store it in the session ( I don't like this if I can avoid it ) 3 - don't store it at all, redirect so some value is on your URL that allows you to rebuild the data from the database.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          M 1 Reply Last reply
          0
          • C Christian Graus

            Everything is going to work the same way, your options are: 1 - store it in viewstate ( this means it goes down to the client every time, making it insecure, and also making your pages huge ) 2 - store it in the session ( I don't like this if I can avoid it ) 3 - don't store it at all, redirect so some value is on your URL that allows you to rebuild the data from the database.

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            M Offline
            M Offline
            Member 4700225
            wrote on last edited by
            #5

            Thanks so much Christian. It was really helpful. I thought there could be a better way that I don't know, but looks like there isn't. Off course I'll not use ViewState, probably, I'll use the Session.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups