寫一個簡單的登陸控制項

來源:互聯網
上載者:User
控制項 login.ascx

由於在頁面上很頻繁使用登陸,把它做成一個控制項是很有必要的,下面就是我寫的一個簡單的登陸控制項,大家可以根據的需要完善一下。

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Oledb" %>
<script language="VB" runat="server">
Sub Page_Load(sender As Object,e As EventArgs)
session("Accessed")=false
If session("UserName")="" And Not IsPassLogin() then
lblLogin.visible=true
lblMessage.visible=false
IsPassLogin()
else
lblMessage.Text=ShowPrompt(True)
lblMessage.visible=true
lblLogin.visible=false
End If
End Sub
'使用者登陸驗證
Public Function IsPassLogin() As Boolean
Dim MyConnection As OledbConnection
Dim strConnection As String="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("DataBase/popmarry.mdb")
MyConnection=New OledbConnection(strConnection)
Dim sqlCommand="SELECT * FROM InMember WHERE MemberID='" & UserID & "'" & " AND Pwd='" & UserPassword & "'"

Dim MyAdapter As New OleDbDataAdapter(sqlCommand,MyConnection)
Dim ds As DataSet=New DataSet()
MyAdapter.Fill(ds,"InMember")
Dim dt As DataTable=ds.Tables("InMember")
If dt.Rows.Count>0 Then
Session("UserName")=UserID
Return(true)
Else
Return(false)
End If
End Function

'顯示登陸資訊
Public Function ShowPrompt(bolInfo As Boolean) As String
If bolInfo Then
Dim strWelcome As String
strWelcome="<table width='165' cellpadding='3' border='0' align='center'><tr><td align='center'>歡迎您,<font color='#FF0000'>" & Session("UserName") & "</font></td></tr><tr><td align='center'>"
strWelcome &="<table width='150' border='0'><tr><td align='center'>狀態: <font color='#FF3300'>新婚網會員</font></td></tr></table>"
strWelcome &="<table width='110' border='0'><tr><td align='center'>控制台</td><td align='center'><a 定義UserPassword的屬性
Public Property UserPassword As String
Get
UserPassword=txtUserPassword.Text
End Get
Set
txtUserPassword.Text=value
End Set
End property
</script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="168">
<tr>
<td>
<asp:label ID="lblLogin" runat="server">
<table width="168" height="60">
<tr>
<td width="63" align="center">使用者名稱:</td>
<td colspan="2" align="left">
<asp:textbox BorderStyle="Groove" Height="20" Width="90px" runat="server" ID="txtUserID" />
<asp:requiredfieldvalidator ControlToValidate="txtUserID" Display="Dynamic" ID="rfdUserID" runat="server" ErrorMessage="<font color=red>*</font>" />
</td>
</tr>
<tr>
<td align="center">密 碼:</td>
<td colspan="2" align="left">
<asp:textbox BorderStyle="Groove" Height="20" Width="90px" runat="server" TextMode="Password" ID="txtUserPassword" />
<asp:requiredfieldvalidator ControlToValidate="txtUserPassword" Display="Dynamic" ID="rfdPassword" runat="server" ErrorMessage="<font color=red>*</font>" />
</td>
</tr>
<tr align="center">
<td colspan="3"><input name="image" type="image" src=http://www.163design.net/n/i/"images/form_login.gif" width="40" height="18" border="0">
  <img src=http://www.163design.net/n/i/"images/form_reg.gif" width="40" height="18" border="0"> 
<img src=http://www.163design.net/n/i/"images/form_lost.gif" width="60" height="18" border="0"></td>
</tr>
</table>
</asp:label>
<asp:label ID="lblMessage" runat="server">
<table width="100%">
<tr>
<td> </td>
</tr>
</table>
</asp:label>
</td>
</tr>
</table>



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。