Session.Abandon

R

Random

I have an <asp:LinkButton runat="server" id="btnLogin"/> control that I use
in my page header for login/logout link. Depending on the session state
when the page loads, I set the .Text and .PostBackUrl properties, like so...

Private Sub Page_Load(...)
If CType(Session("started"), Boolean) = False Then
WriteLogin()
Else
WriteLogout()
End If
End Sub

Private Sub WriteLogin()
btnLogin.Text = "LOGIN"
btnLogin.PostBackUrl = "../login.aspx"
End Sub

Private Sub WriteLogout()
btnLogin.Text = "LOGOUT"
End Sub

Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
If CType(sender, System.Web.UI.WebControls.LinkButton).Text = "LOGOUT"
Then
Session.Abandon()
WriteLogout()
End If
End Sub

The problem I'm having is, I have to click on 'LOGOUT' twice to work. I'm
thinking the Session.Abandon statement doesn't really work until the page
finishes processing and the content is flushed to the client. That confused
me, though, because the btnLogin.Text still says 'LOGOUT' after the first
click. What is happening here?
 
R

Rutger Smit

Random said:
I have an <asp:LinkButton runat="server" id="btnLogin"/> control that I use
in my page header for login/logout link. Depending on the session state
when the page loads, I set the .Text and .PostBackUrl properties, like so...

Private Sub Page_Load(...)
If CType(Session("started"), Boolean) = False Then
WriteLogin()
Else
WriteLogout()
End If
End Sub

Private Sub WriteLogin()
btnLogin.Text = "LOGIN"
btnLogin.PostBackUrl = "../login.aspx"
End Sub

Private Sub WriteLogout()
btnLogin.Text = "LOGOUT"
End Sub

Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
If CType(sender, System.Web.UI.WebControls.LinkButton).Text = "LOGOUT"
Then
Session.Abandon()
WriteLogout()
End If
End Sub

The problem I'm having is, I have to click on 'LOGOUT' twice to work. I'm
thinking the Session.Abandon statement doesn't really work until the page
finishes processing and the content is flushed to the client. That confused
me, though, because the btnLogin.Text still says 'LOGOUT' after the first
click. What is happening here?


Everything that happens in the same request as the Session.Abandon still
has the Session state. At the next requesty the sessionstate will be
cleared.

//Rutger

--

//Rutger

DoDotNet@KICKTHIS_Gmail.com
www.RutgerSmit.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ReturnURL 0
Why do I need to refresh? 2
Invisible folder 0
reload of page required after formsAuthentication signout / logout? 1
Make button invisible 1
Session Problems 2
Forms Login/Logout 3
Session 6

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top