Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello programmers, got a problem here as you see ive created a log-in page where i put session to be sent to masterpage when the login the correct. My problem is how can i input the data to master page. Please help
My code content page:
Imports System.Data.SqlClient
Imports System.Data

Partial Class Login
    Inherits System.Web.UI.Page
    Dim con As SqlConnection = New SqlConnection("Data Source=ML0003135586\SQLEXPRESS;Initial Catalog=ecom;Integrated Security=True")
    Dim sqlstr As String = String.Empty

    Protected Sub log_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles log.Click
        Dim strUserURL As String
        sqlstr = "SELECT * FROM [Users] WHERE ([Username]=@Username) AND ([Password]=@Password)"
        con.Open()
        Dim cmd As New SqlCommand(sqlstr, con)
        cmd.Parameters.AddWithValue("@Username", tbUser.Text)
        cmd.Parameters.AddWithValue("@Password", tbPass.Text)
        strUserURL = cmd.ExecuteScalar()
        con.Close()
        If strUserURL <> "" Then
            lblInvalid.Text = ""
            FormsAuthentication.SetAuthCookie(tbUser.Text, True)
            Session("username") = tbUser.Text
            Response.Redirect("Home.aspx")
        Else
            lblInvalid.Text = "Sorry... try again..."
        End If
    End Sub
End Class

Home.aspx code
Partial Class Home
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim username As String = Session("username")
        Dim mpLabel As Label
        mpLabel = CType(Page.Master.FindControl("lblName"), Label)
        username = "" + mpLabel.Text
    End Sub
End Class

ive tried that code but is not working please help
Posted
Updated 14-Aug-11 19:28pm
v2

1 solution

Have you tried adding session on your master page?
codes
VB
Dim str As String
str = Convert.ToString(Session("username"))
lblName.Text = str
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900