我正在使用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
答案 0 :(得分:2)
传递变量的快速而肮脏的方法是使用会话变量,如:
会话(“CurName”)= CurName