坚持在回传C#对象 [英] Persist c# objects across postbacks
问题描述
我有一个具有C#code-背后做一些东西在Page_Load()方法(如查询数据库,并提出一些其他调用来填充数据对象)一个asp.net页面。然后,我在页面上显示该数据。这一切工作正常。我设置了一对夫妇回传,使被点击列表框的值时,面板控制充满了相应的对象的数据的其余部分。我想回发是这样做的正确的方式,但是这会导致(整个班级?)重新调用,从而重新初始化我的对象,破坏我想保留的数据。
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...
我发现关于坚持JavaScript对象的许多问题,但没有真正似乎解决这个问题。我使用.NET 4.0
I've found many questions regarding persisting Javascript objects, but nothing that really seems to address this. I'm using .Net 4.0
推荐答案
把物体插入会话
当前用户。
这篇关于坚持在回传C#对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!