Why do I need to refresh?

G

Guest

Hi all!
Here's the situation
I have a frame set with 3 frames, banner, contents and main.
I have my login.aspx in banner and after login, I redirect back to
index.aspx where my frameset at.
There should be some change on banner and main but it didn't happen, I need
to press F5 in order for the change to take place.
Here's the change:
banner : disable login button and enable logout button
main : change the frame source to other page.
Why is this happening?
Thanks in advance.

codes of banner.aspx
************************************************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Session("login") = True Then
lblResult.ForeColor = System.Drawing.Color.Black
lblResult.Text = "Welcome, " & Session("name") & "!"
If lblResult.Visible = False Then
lblResult.Visible = True
End If
If btnLogout.Enabled = False Then
btnLogout.Enabled = True
End If
If btnLogin.Enabled = True Then
btnLogin.Enabled = False
End If
End If
End Sub

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogin.Click

Dim Conn As SqlConnection
Dim Reader As SqlDataReader
Dim Cmd As New SqlCommand

Try
Conn = New
SqlConnection("server=(local);Trusted_Connection=yes;database=Attendance")
Conn.Open()
Cmd.Connection = Conn
Cmd.CommandText = "SELECT * FROM Staff WHERE StaffID='" &
txtStaffID.Text.Trim & "'"
Reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)

If Not Reader.HasRows Then
If lblResult.Visible = False Then
lblResult.Visible = True
End If
lblResult.ForeColor = System.Drawing.Color.Red
lblResult.Text = "Invalid Login Datas!"
Else
Reader.Read()
If Reader.GetValue(5) = txtPassword.Text.Trim Then
Session("id") = Reader.GetValue(5)
Session("login") = True
Session("name") = Reader.GetValue(1)
Response.Redirect("index.aspx", False)
Else
Session("login") = False
End If
End If
Catch ex As Exception
Session("err") = ex.ToString & "<br>" & ex.HelpLink
Response.Redirect("error.aspx")
Finally
Conn.Close()
Cmd.Dispose()
End Try
End Sub
************************************************************

codes of index.aspx
************************************************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Session("login") = True Then
main.Attributes("src") = "link.aspx"
End If

End Sub
************************************************************
 
G

Guest

pop,
when the user clicks Login button , The 'Private Sub Page_Load' gets
executed before 'Private Sub btnLogin_Click'

So your session variable Session("login") has not been set to True when you
hide/show login-logout buttons in 'Private Sub Page_Load' , the first time

Only When you refresh the page again (with F5 or another event) the 'Private
Sub Page_Load' gets to know the Session("login") has been set to true by last
click event.





Sreejith
 
G

Guest

Thanks a lot.
I found out that by using PreRender can solve this but I still don't figure
out how to do it.
Can anyone show me with an example?
Thanks in advance.
 

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

Members online

Forum statistics

Threads
474,056
Messages
2,570,441
Members
47,119
Latest member
NoeliaIrby

Latest Threads

Top