• 0

How to save ArrayList object to ViewState?


Question

//for example

[serializable]

class MyItem

{

public string = "";

}

I created several MyItem objects and saved them to an ArrayList "al". Then I store the arraylist to ViewState

ViewState["Items"] = al;

When the page postback, I retrieve the arraylist

ArrayList al = (ArrayList)ViewState["Items"];

But there are nothing in al. Why?

5 answers to this question

Recommended Posts

  • 0
  LRoling said:
Is there a specific reason you are using the ViewState? Couldn't you just Session the data?

I want to design a simple search page, when the search is done, you must display the results, so I want to save the results to a Arraylist that I can display them again without reconnect the database when the page postpack. Do you have any other good plans? thanks.

  • 0
  zhwcn said:
I want to design a simple search page, when the search is done, you must display the results, so I want to save the results to a Arraylist that I can display them again without reconnect the database when the page postpack. Do you have any other good plans? thanks.

Use either Session or System.Web.Caching.Cache. Don't use the ViewState if you can avoid it.

  • 0

The question is: when are you storing your ArrayList in ViewState and when are you trying to access the stored value again? Could be that the ViewState is not yet initialized when you're trying to access it to fetch the ArrayList.

If you're using Visual Studio you could try to debug and step through your code to ensure that things are done in correct order (ASP.NET Page Life Cycle).

  • 0
  jpalo said:
The question is: when are you storing your ArrayList in ViewState and when are you trying to access the stored value again? Could be that the ViewState is not yet initialized when you're trying to access it to fetch the ArrayList.

If you're using Visual Studio you could try to debug and step through your code to ensure that things are done in correct order (ASP.NET Page Life Cycle).

yeah, you are right. I modified my code, put the viewstate retrieve block into OnLoad(), this time it works as I expect. Thank U!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Not Netflix's fault and they had to switch to content creation. Content owners jacked up prices, won't allow them renew, and didn't give them the option to license new content.
    • As sphbecker said you obviously missed the hidden /s at the end of my comment.
    • Everything I have ever read about Windows 11's telemetry collection over Windows 10 is that it's minor. Why would Microsoft be leaving data on the table with Windows 10? That doesn't even pass the smell test. LOL Windows 11 can be less performant in certain cases (and faster in others) but that has always been blamed on extra security features in WIn11. Windows 11 when I used it always ran fine for me. I would say If you were really concerned about either you wont be running Windows to begin with or limited to a secondary machine.
    • There was a brief time when they allowed Netflix (ad free) to pretty much license everything affordable, and piracy actually went down. When they saw how much Netflix was making, number of users, etc, they stopped allowing renewing of content and withholding it to make their own streaming services.
    • Wine 10.9 released bringing EGL support for all graphic drivers and several bug fixes by David Uzondu Wine 10.9 is out now, bringing EGL library support for all graphics drivers. For anyone trying to get Windows software running smoothly on Linux or macOS, this unification of EGL access promises more consistent graphical behavior and potentially better performance for applications that lean on it. EGL is a crucial bridge, letting things like OpenGL ES (often used in mobile apps, some desktop applications, and even games) talk to your system's window manager. Having it standardized across all drivers under Wine means fewer instances where an app might render beautifully on one setup but turn into a pixelated mess or refuse to launch on another. Gamers, and especially those dabbling with newer Windows titles, will appreciate that the bundled vkd3d, Wine's secret sauce for translating Direct3D 12 calls to Vulkan, has been upgraded to version 1.16. Every update to vkd3d generally means improved compatibility with the latest and greatest Direct3D 12 titles and ongoing fixes for stubborn ones. Considering vkd3d is a core component for projects like Steam's Proton, which enables a massive library of Windows games on Linux and the Steam Deck, this update is certainly welcome news. Key improvements vkd3d 1.16 brings include: DXIL shaders are now supported in the default configuration, raising the maximum supported shader model to 6.0. Graphics pipeline state objects can be created from shaders with embedded root signatures. Implementation of the SetEventOnMultipleFenceCompletion() method of the ID3D12Device1 interface. Experimental support for compiling DXIL shaders is now a fully supported and enabled-by-default feature in libvkd3d-shader. libvkd3d-shader has initial support for geometry shaders and various new intrinsic functions. The vkd3d demos now work on both Microsoft Windows and Apple macOS builds. Moving on, support for compiler-based exception handling with Clang also makes an appearance; this is a technical enhancement that can lead to greater stability for applications built using that specific compiler when they are run through Wine, reducing unexpected crashes for a subset of programs. Furthermore, Wine 10.9 introduces initial groundwork for generating Windows Runtime metadata in WIDL, its Interface Definition Language tool. As always with development releases, there is a solid list of bug fixes, 34 of them in this particular version. Some notable ones include resolving fullscreen issues with the classic 3D Pinball - Space Cadet, fixing display artifacts in Empire Earth, sorting out text display problems in the EA app launcher, and addressing crashes or visual glitches in games like Dyson Sphere Program and platforms like Geekbench 6. If you're interested in trying out this release, follow the installation instructions for your platform: Ubuntu/Debian, Fedora, or macOS. Installation guides for other platforms, including Slackware, are also available. The release notes for version 10.9 are available here.
  • Recent Achievements

    • First Post
      ClarkB earned a badge
      First Post
    • Week One Done
      Epaminombas earned a badge
      Week One Done
    • Week One Done
      Prestige Podiatry Care earned a badge
      Week One Done
    • Week One Done
      rollconults earned a badge
      Week One Done
    • Week One Done
      lilred1938 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      143
    2. 2
      Xenon
      130
    3. 3
      ATLien_0
      124
    4. 4
      +Edouard
      102
    5. 5
      snowy owl
      97
  • Tell a friend

    Love Neowin? Tell a friend!