如何避免使用Session [英] How to avoid using Session

查看:295
本文介绍了如何避免使用Session的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数据网的接口。当我添加元数据网格,我添加它也融入这是我的数据网格的数据源列表属性。在这里,我的清单在申报code-背后:

i have an interface that contains data-grid. When i add element to data-grid, i add it also into List property that is the data-source of my Data-grid. Here the declaration of my list in code-behind:

Public Property listeSpecialite() As List(Of RECSPECIALITECONCOURS)
    Get
        Return Session("specialite")
    End Get
    Set(ByVal value As List(Of RECSPECIALITECONCOURS))
        Session("specialite") = value
    End Set
End Property

和这里是code当我添加元素,数据网格:

and here is the code when i add element to Data Grid :

 Protected Sub gridsecialite_ItemCommand(source As Object, e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gridsecialite.ItemCommand
    If e.CommandName = "Insert" Then
        Dim dropSpecialite As DropDownList = CType(e.Item.FindControl("txtSpecialite_Footer"), DropDownList)

        Dim specialite As New RECSPECIALITECONCOURS
        specialite.CODESPECIALITE = IGS.ChercherParIdInt(Of GENSPECIALITE)(CInt(dropSpecialite.SelectedValue))
        listeSpecialite.Add(specialite)
        gridsecialite.DataSource = listeSpecialite            
        gridsecialite.DataBind()            

    End If
 End Sub

和用户的点击保存,我保存所有的元素在我的名单数据库。

and in user click save, i save all element in my list to database.

我怎么能保存列表的元素,而无需使用会话。 (我的老板说,这是不好的存储会话性能原因元素列表)

how can i save element of the list without the use of session. (my boss say that it's not good to store list of element in session-performance reason)

推荐答案

您可以使用的 ViewState中存储 listeSpecialite 。只要确保理解它是如何工作,确保比赛你所需要的。

You can use ViewState to store listeSpecialite. Just make sure to understand how it works to ensure that match what you need.

视图状态具有其自身的缺点。在B64和负载页面生命周期过程中更多的时间序列化/反序列化,编码/ deocding /恢复页面视图状态等。此外,在默认情况下,ViewState是在一个隐藏字段发送到客户端。这种增加带宽。

Viewstate has its own drawbacks. More process time for serialization/deserialization, encoding/deocding in B64 and for the page lifecycle in load/restore viewstate of the page, etc. Also, by default, viewstate is sent to the client in a hidden field. This increase bandwidth.

无论如何,如果你的列表中有不能坚持你的当前视图我会使用视图状态

Anyway, if your list has not to be persisted out of your current view I would use Viewstate.

编辑:

随着1000项目列表视图状态将hurge。如何从数据库中读取持久化的项目,并保持在ViewState中刚刚添加的项目?你可以检索数据库的项目,从视图状态检索项目,结合并绑定到数据网格。这是另一种策略,以避免在读取数据库的成本和会话视图状态hurge每个回发。

With list of 1000 items viewstate will be hurge. How about read from data base persisted items and keep in viewstate just the added items?. You could retrieve items of database, retrieve items from viewstate, combine and bind to datagrid. It is another strategy to avoid session and hurge viewstate at the cost of read database every postback.

正如我所说的,没有银弹... :-P

As I said, there is no silver bullet... :-P

这篇关于如何避免使用Session的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆