Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persist c# objects across postbacks

I've got an asp.net page that has c# code-behind that does some stuff in the Page_Load() method (like query a database and make a few other calls to populate objects with data). I then display this data on the page. This all works fine. I set up a couple of postbacks so that when a value in a listbox is clicked, a panel control is filled with the rest of the corresponding object's data. I thought postbacks were the right way to do this, but this causes the (entire class?) to be re-called, which re-initializes my objects and destroys the data I want to keep.

Will some form of partial-postback solve this problem, or is there a better way to implement what I'm trying to do?

I don't want to re-populate the objects every time a postback is called, as that takes a database query, and I want to avoid re-querying every time something is clicked...

I've found many questions regarding persisting Javascript objects, but nothing that really seems to address this. I'm using .Net 4.0

like image 958
uscere90 Avatar asked Jun 10 '11 16:06

uscere90


People also ask

What is persistent in C?

Persistent dataWhen a C program exits, all of its global variables, local variables, and heap-allocated blocks are lost. Its memory is reclaimed by the operating system, erased, and handed out to other programs.

What does it mean to persist a file?

Persistent storage is any data storage device that retains data after power to that device is shut off. It is also sometimes referred to as non-volatile storage. Magnetic media, such as hard disk drives and tape are common types of persistent storage, as are the various forms of Optical media such as DVD.

What is persistent data type?

A persistent data structure is a data structure that always preserves the previous version of itself when it is modified. They can be considered as 'immutable' as updates are not in-place. A data structure is partially persistent if all versions can be accessed but only the newest version can be modified.

What is ephemeral data structure?

∎ An ephemeral data structure is one for. which only one version is available at a time: after an update operation, the structure as it existed before the update is lost. ∎ A persistent structure is one where. multiple versions are simultaneously accessible: after an update, both old and new versions can be used.


1 Answers

Put the objects into the Session for the current user.

like image 120
Yuck Avatar answered Sep 21 '22 16:09

Yuck