Persist C # objects via postbacks

I have an asp.net page that has C # code that does some things in the Page_Load () method (for example, query the database and make several other calls to populate the objects with data). Then I show this data on the page. All of this works great. I set up a couple of postbacks, so when the value in the list is clicked, the control panel is populated with the rest of the corresponding object data. I thought postbacks are the right way to do this, but it causes a callback (the whole class?), Which reinitializes my objects and destroys the data I want to save.

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 this takes a query to the database, and I want to avoid re-populating every time that something is clicked ...

I found a lot of questions regarding persistent Javascript objects, but nothing that really seems to affect this. I am using .Net 4.0

+6
source share
3 answers

Put the objects in Session for the current user.

+3
source

Put all your initialization files in (!IsPostback) { } and use partial (!IsPostback) { } . Thus, the initialization code will not be called again during the postback.

+2
source

Why don't you cache the object?

API caching, using the cache object: http://msdn.microsoft.com/en-us/library/aa478965.aspx#aspnet-cachingtechniquesbestpract_topic4

+1
source

Source: https://habr.com/ru/post/890237/


All Articles