.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
写一个简单的登陆控件

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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 onclick='return LogoutConfirm()' href='login/logout.aspx'>退出登录</a></td></tr></table></td></tr></table>"
  '返回成功登陆信息
  Return(strWelcome)
 Else
  Dim strError As String
  strError="<table width='130'align='center'><tr><td>登录失败:<br>1.用户名或密码错误<br>2.此帐号被锁定<br>3.未<a href='../register/Register.asp' target='_blank'>注册</td></tr>"
  strError &="<tr><td height='20'><center><a href='javascript:onclick=history.go(-1)'>【返回】</a></center></td></tr></td></tr></table>"
  '返回登陆失败信息
  Return(strError)
 End If
End Function

Public Property UserID As String
 Get
  UserID=txtUserID.Text
 End Get
 Set
  txtUserID.Text=value
 End Set
End Property

'定义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="images/form_login.gif" width="40" height="18" border="0">
              &nbsp; <img src="images/form_reg.gif" width="40" height="18" border="0">&nbsp;
              <img src="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>&nbsp;</td>
          </tr>
        </table>
  </asp:label>
  </td>
    </tr>
  </table>




相关文章

相关软件