Session.Abandon

  • Thread starter Thread starter Random
  • Start date Start date
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?
 
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
 
Back
Top