469,963 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Session Not Maintaing State

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.

Apr 18 '07 #1
3 1541
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

Apr 18 '07 #2
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!

Apr 18 '07 #3
On Apr 18, 2:46 pm, r...@rediffmail.com wrote:
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!- Hide quoted text -

- Show quoted text -
You must have a statement that stores the value into the Session
variable. Now, where is that statement? Should it be running each time
the page loads (or whatever event handler fires), or should it only be
running under certain circumstances (i.e. first page load, all loads
other than first page load, etc..). Check to make sure the assignment
is occuring under the right conditions. For example, if you wanted
this to occur only AFTER the first page load, you would set it up like
this...

void Page_Load()
{
if(this.Page.IsPostBack)
{
// this code block runs only if the page is NOT being loaded
for the first time
[your code to do something]
}
}

If you already are way beyond this then I apologize! I remember it
took me a while to understand stuff like this.

Apr 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John A Grandy | last post: by
10 posts views Thread by tshad | last post: by
2 posts views Thread by archana | last post: by
11 posts views Thread by Glenn | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.