473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 1721
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Grimpo | last post by:
I have a very odd situation here. I have an administration page, where based on a users permissions, a recordset is called from the SQL server which has a list of paths to "Module Menus". Each of...
2
by: John A Grandy | last post by:
for high traffic public websites , what are the proven options for session-state storage & management ? is an out-of-process state-server generally preferred over a sql-server ? what are the...
1
by: Johan Nedin | last post by:
Hello! I have a problem with SQLSession state on my ASP.NET pages. SQLSession state behaves very different from InProcess session state, which I think is very bad. I can understand some of...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
2
by: archana | last post by:
Hi all, I am new to asp.net. I am not very much clear in concept of viewstate. CAn anyone help me in understanding this concept. I have one question regarding viewstate. I have one aspx...
11
by: Glenn | last post by:
Hi I've been experimenting with managing state using the Session object. I've created a simple WS with a couple of methods, one which sets a string value, another that retrieves it. Each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.