Firstly, you have a ContentPlaceHolder
inside another ContentPlaceHolder
and I can't see any reason for this.
<asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server">
<asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">
To the matter in hand, I would hide the controls contained within the ContentPlaceHolder
depending on whether the user is logged in or not, rather than hiding the placeholder, however this is up to you. I would also add the userid
column to your SQL query.
The follwing should get you started, note this is untested off the top of my head:
SELECT userid, username, password FROM users ....
If dr.HasRows Then
Session("userid") = dr("userid")
ElseIf dr.HasRows = False Then
lblRegister.ForeColor = Drawing.Color.Red
lblRegister.Text = "Incorrect Username/Password."
End If
Now that you have this, you can check the Session variable on Page_Load
to see if the user is logged in.
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Session("userid") <> "" Then
txtLoginUser.Visible = False
txtLoginPass.Visible = False
Else
'Set your label text here, query the database to get the First and Second name of the user using the `userid`
End If
End Sub
EDIT You need to close your readers after you have finished reading:
dr.Close()
and datareader.Close()
Also this line lblLoggedIn.Text = "Welcome," + txtLoginUser.Text
needs to be:
lblLoggedIn.Text = datareader("name").ToString() & " " &
datareader("surname").ToString()