欢迎光临
我们一直在努力

写一个简单的登陆控件-.NET教程,组件控件开发

建站超值云服务器,限时71元/月

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=130align=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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 写一个简单的登陆控件-.NET教程,组件控件开发
分享到: 更多 (0)