将asp.net登录值转移到其他页面,但我想显示员工姓名?

时间:2011-11-23 22:56:55

标签: asp.net vb.net

我正在使用asp.net创建登录页面,代码隐藏在vb.net中,我是新手:D。我的问题是如何将登录名传递给另一个页面。首先,每当我登录时,它将识别它是否是msgbox中显示的管理员。用户要求是员工姓名显示为登录而不是用户名。这是我的代码。提前谢谢。

受保护的子Button1_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理Button1.Click

    Dim cmd1 As New SqlCommand
    Dim rdr As SqlDataReader

    cmd1.Connection = cn
    cmd1.Connection.Open()
    cmd1.CommandText = "SELECT * from UserTable WHERE Username ='" & txt_username.Text & "'"
    rdr = cmd1.ExecuteReader

    If rdr.HasRows = True Then
        rdr.Read()
        If txt_username.Text = rdr.Item(0) And txt_password.Text = rdr.Item(3) Then
            CurPos = rdr.Item("Type")
            CurUser = rdr.Item("Username")
            CurName = rdr.Item("EmployeeName")

            If rdr.Item(4) = "ADMINISTRATOR" Then
                MsgBox("WELCOME! " & rdr.Item(4), MsgBoxStyle.Information)
                Main.lbl_name.Text = CurName.ToUpper       'it's not working
                POS.lbl_cashier.Text = CurName.ToUpper     ' it's not working
                Response.Redirect("ACESCHOOLSUPPLIES.aspx")
                cmd1.Connection.Close()
                'Me.Dispose()
            Else
                MsgBox("WELCOME! " & rdr.Item(4), MsgBoxStyle.Information)

                cmd1.Connection.Close()
                Response.Redirect("POS.aspx")

            End If

1 个答案:

答案 0 :(得分:2)

传递变量的快速而肮脏的方法是使用会话变量,如:

会话(“CurName”)= CurName

其他方式:http://www.4guysfromrolla.com/articles/020205-1.aspx