On Apr 18, 8:22 pm, Joey <joey.pow...@topscene.comwrote:
On Apr 18, 8:59 am, r...@rediffmail.com wrote:
A ASPX Form has a TextBox & a Button. Users enter their username in
the TextBox & submit the Form after which records pertaining to the
username get retrieved from a MS-Access database table & displayed in
a DataGrid. The DataGrid also provides pagination.
Sub Page_Load(......)
If Not(Page.IsPostBack) Then
'do something
Else
Dim strSQL As String
Dim strUserName As String
strUserName = txtUserName.Text
Session("UserName") = strUserName
Response.Write("UserName: " & Session("UserName"))
strSQL = "SELECT............WHERE UserName = '" &
Session("UserName") & "'"
'some more code comes here
End If
End Sub
Assume that I enter the username Ronnie in the TextBox & submit the
Form. The DataGrid correctly displays the 1st set of records (note
that the records are paginated) but strangely when I click any of the
paging links (or for that matter, any link that re-posts the Form),
the variable Session("UserName") becomes empty! It no longer holds the
username; it gets lost! I have turned on EnableSessionState in the
Page directive as well but that doesn't make any difference.
Can someone please give me some clues on what could be causing this? I
also tried using ViewState("UserName") instead of Session("UserName")
but that doesn't resolve the issue.
In asp.net 2.0 if you are modifying/saving the contents of a file, and
it is outside of the App_Data folder, I think it will cause an
AppDomain restart. This will kill your Session data. Do a search for
AppDomain restart, and you'll find more info.
JP- Hide quoted text -
- Show quoted text -
Joey, when a user comes to the page for the first time, only the
TextBox & the Button are visible to users whereas the DataGrid remains
hidden. Assuming that the username entered by a user gets validated
successfully against the MS-Access database, the TextBox & the Button
becomes invisible & the DataGrid becomes visible..When any link is
clicked under such circumstances so that the page posts back to
itself, the Session variable loses the value it was holding prior to
clicking the link.
After some experiments, I concluded that if I keep the TextBox visible
when the DataGrid is displayed & then I click any link to post the
page, then the Session variable doesn't lose the value it had stored
when the page was posted for the first time but if the TextBox is made
invisible when the DataGrid is visible, then only the Session variable
loses the value.
Your opinion on this??
Though I am not 100% sure, I don't think this has got to do anything
with AppDomain or App_Data; it's the visibility of the TextBox that's
causing the Session variable to lose/retain its value.
I never anticipated this to be such a tough question to answer!