我已經建立了一個類作爲外觀來訪問我的應用程序的會話變量。在這個應用程序中,我將一個特定僱主的整個數據集存儲爲一個會話變量。爲什麼添加到會話數據表的行在頁面刷新時消失了?
在其中一個子頁面中,我有一個按鈕,它將一行添加到存儲在該數據集中的現有表中。
Dim curRow As Data.DataRow = mySession.tWorksiteOtherMeasures.NewRow()
curRow("lngWorksiteID") = getSelectedWorksiteID(getSelectedSiteID())
curRow("strMeasure") = ""
curRow("lngStatusID") = -1
curRow("lngPoints") = -1
mySession.tWorksiteOtherMeasures.Rows.Add(curRow)
該類訪問使用該表:
Public Shared ReadOnly Property tWorksiteOtherMeasures() As Data.DataTable
Get
Return dsEmployer.Tables(TWORKSITEOTHERMEASURES_IDX)
End Get
End Property
Public Shared Property dsEmployer() As Data.DataSet
Get
Return CType(HttpContext.Current.Session(DSEMPLOYER_IDX), Data.DataSet)
End Get
Set(ByVal value As Data.DataSet)
HttpContext.Current.Session(DSEMPLOYER_IDX) = value
End Set
End Property
當在代碼中加入該行的行計數增量和行存在。一旦超出該範圍,由於按鈕包含在updatePanel中,頁面將刷新。當發生這種情況時,我再次點擊添加按鈕,在該代碼運行後,該項目的行計數重置爲0和1。之前添加的行不見了。
我錯過了什麼?如果你願意,隨意發佈其他語言的例子,我只是碰巧在工作中使用VB.NET。 :)
這裏是如何的數據集從網絡服務分配:
Public Shared Sub loadDSEmployer(ByVal strUserId As String)
Dim myService As New someservice.service
mySession.dsEmployer = myService.GetEmployerAndSites(strUserId, isInternal)
End Sub
查看最初如何在會話中存儲對象可能會有幫助。你能告訴我們mySession的代碼嗎? – 2010-02-25 17:38:53
好的,添加到底部。 – 2010-02-25 17:48:55