用asp.net制作的登录页面
|
源代码网整理以下一般在一个系统里总会有一个登录页面,同时,登录页面的制作对于所有系统开发者来说,都是必经之路! 源代码网整理以下首先,我们先来看看这个登录页面里主要的功能是: 源代码网整理以下1. 验证用户输入的数据是否完整! 源代码网整理以下2. 验证用户输入的数据是否满足要求,比如:姓名是否是4-10位字符,密码是否是4-8位字符。 源代码网整理以下3. 同时在这个页面里还用到了asp.net的Pagelet(网页配件)。 源代码网整理以下现在,我们一起来看看具体是怎么制作这个页面的。 源代码网整理以下第一. 怎样验证用户输入的数据是否完整,这个做过asp的人都能理解。不同的是在asp.net里显示信息的话是用Label.text=…,表示这个 源代码网整理以下if userid="" and password=""then 源代码网整理以下 Label2.Text &= "请输入姓名和密码!" 软件开发网 www.mscto.com
源代码网整理以下exit sub 源代码网整理以下 源代码网整理以下else 源代码网整理以下if userid=""then 源代码网整理以下 Label2.Text &= "请输入姓名!" 软件开发网 www.mscto.com 源代码网整理以下exit sub 源代码网整理以下 软件开发网 www.mscto.com 源代码网整理以下else 源代码网整理以下if password=""then 源代码网整理以下 Label2.Text &= "请输入密码!" 源代码网整理以下exit sub 源代码网整理以下第二.验证用户输入的数据是否满足要求 源代码网整理以下在这里使用asp.net的Regularexpressionvalidator控制元件,Regular Expression是一种功能强大的字符串定义规则,让我们直接来看个实例 源代码网整理以下 源代码网整理以下密码 :[a-zA-Z0-9]{4,8} 源代码网整理以下有关以上定义的Regular Expression字符串,说明如下: 源代码网整理以下[]:用来定义可接受的字符,a-z表示小写的a-z都是可以接受的字符,A-Z也是,还有数字0-9都是可以接受的。 源代码网整理以下{}:用来定义必须输入的字符数,{4,10}表示至少含有4个字符,最多含有10个字符。 软件开发网 www.mscto.com 源代码网整理以下现在让我们来看看Regular Expression在网页中的布置方法: 软件开发网 www.mscto.com 源代码网整理以下<td>姓名:</td> 源代码网整理以下 <td><asp:TextBox id="Text1" runat="server"/> 源代码网整理以下 <asp:regularexpressionvalidator id="valid1" runat="server" controltovalidate="text1" 软件开发网 www.mscto.com 源代码网整理以下 validationexpression="[a-zA-Z0-9]{4,10}"> 源代码网整理以下 (请输入4-10位字符) 源代码网整理以下 </asp:regularexpressionvalidator><p> 软件开发网 www.mscto.com 源代码网整理以下 </td> 源代码网整理以下 </tr> 源代码网整理以下 <tr> 源代码网整理以下 <td>密码:</td> 源代码网整理以下 <td><asp:TextBox id="Text2" TextMode="Password" runat="server"/> 软件开发网 www.mscto.com 源代码网整理以下 <asp:regularexpressionvalidator id="valid2" runat="server" controltovalidate="text2" 源代码网整理以下 validationexpression="[a-zA-Z0-9]{4,8}"> 源代码网整理以下 (请输入4-8位字符) 源代码网整理以下</asp:regularexpressionvalidator><p> 源代码网整理以下一般Regular Expression它是放在要控制的表单元件后面。在网页中,E-mail,电话,地址是常见的输入栏,具体使用方法我们通过上面的例子 源代码网整理以下第二. 同时在这个页面里还用到了asp.net的Pagelet(网页配件)。 源代码网整理以下Pagelet(网页配件)?何谓Pagelet(网页配件),说的通俗点的话,就想是圣诞树上的小挂件, 软件开发网 www.mscto.com 源代码网整理以下看页面的上面部分: 软件开发网 www.mscto.com 源代码网整理以下我的第一个Header 源代码网整理以下2002-4-30 14:49:32 源代码网整理以下 源代码网整理以下 源代码网整理以下学习asp.net找我 源代码网整理以下这个就是两个Pagelet!我们来看看它是怎么制作的: 源代码网整理以下在这个登录页面的最上面的两行代码,表示在使用Pagelet之前,要先将其登录成为网页可以引用的控件,登录header.ascx、footer.ascx的标 源代码网整理以下<%@ register tagprefix="wangmg" tagname="header" src="header.ascx" %> 源代码网整理以下<%@ register tagprefix="wangmg" tagname="footer" src="footer.ascx" %> 源代码网整理以下其中几个属性的设定如下: 源代码网整理以下Src: Pagelet来源文件。 软件开发网 www.mscto.com 源代码网整理以下Tagname: Pagelet类别名称,本例是header和footer。 软件开发网 www.mscto.com 源代码网整理以下TagPrefix:Pagelet类别前导名称,本例是:wangmg。 源代码网整理以下 经过以上的设定之后,header.ascx、footer.ascx将成为网页可以引用的Pagelet,而Pagelet的类别名称是:“wangmg:Table”,定义了类 源代码网整理以下<wangmg:header id ="header1" runat="server" title="我的第一个Header"/> 源代码网整理以下除了必须利用<%@ register %>登录Pagelet之外,使用Pagelet的方法与使用asp.netweb控制元件的方法是完全相同的,也一样可以为Pagelet 源代码网整理以下接下去我们看看header.ascx、footer.ascx 源代码网整理以下header.ascx: 源代码网整理以下<script language="vb" runat="server"> 软件开发网 www.mscto.com 源代码网整理以下public title as string 源代码网整理以下sub page_load(sender as object,e as eventargs) 源代码网整理以下label1.text=title 源代码网整理以下label2.text=cstr(filedatetime(server.mappath(request.filepath))) 源代码网整理以下end sub 源代码网整理以下</script> 源代码网整理以下footer.ascx: 源代码网整理以下 源代码网整理以下<a href="http://asp.6to23.com/musclecn" target="_top"> 软件开发网 www.mscto.com
源代码网整理以下学习asp.net找我</a> 源代码网整理以下 源代码网整理以下 源代码网整理以下在这个页面里设定了title变量,然后在login.aspx页面里定义它的具体内容 源代码网整理以下<wangmg:header id ="header1" runat="server" title="我的第一个Header"/> 源代码网整理以下 源代码网整理以下附:login.aspx: 源代码网整理以下<%@ register tagprefix="wangmg" tagname="header" src="header.ascx" %> 源代码网整理以下<%@ register tagprefix="wangmg" tagname="footer" src="footer.ascx" %> 源代码网整理以下<%@ Import Namespace="System.Data" %> 软件开发网 www.mscto.com 源代码网整理以下<%@ Import Namespace="System.Data.OleDb" %> 源代码网整理以下 源代码网整理以下<script language="VB" runat="server"> 软件开发网 www.mscto.com 源代码网整理以下 sub IsLoginOK (Sender As Object, E As EventArgs) 源代码网整理以下 if page.isvalid then 源代码网整理以下 源代码网整理以下 Dim Provider, SQL, ConnStr As String 源代码网整理以下 dim userid,password,isok as string 源代码网整理以下 源代码网整理以下 userid=trim(text1.text) 源代码网整理以下 password=trim(text2.text) 源代码网整理以下 if userid="" and password=""then 源代码网整理以下 Label2.Text &= "请输入姓名和密码!" 源代码网整理以下exit sub 源代码网整理以下 源代码网整理以下else 源代码网整理以下if userid=""then 源代码网整理以下 Label2.Text &= "请输入姓名!" 源代码网整理以下exit sub 源代码网整理以下 源代码网整理以下else 源代码网整理以下if password=""then 源代码网整理以下 Label2.Text &= "请输入密码!" 源代码网整理以下exit sub 软件开发网 www.mscto.com 源代码网整理以下else 源代码网整理以下 Provider = "Microsoft.Jet.OLEDB.4.0;" 软件开发网 www.mscto.com
源代码网整理以下 ConnStr = "Provider=" & Provider & _ 源代码网整理以下 "Data Source=" & Server.MapPath( "Sample.mdb" ) 源代码网整理以下 Dim Conn As OleDbConnection = New OleDbConnection( ConnStr ) 源代码网整理以下 Conn.Open() 源代码网整理以下 SQL = "Select * From Users Where UserID=´" & UserID & _ 源代码网整理以下 "´ And Password=´" & Password & "´" 软件开发网 www.mscto.com 源代码网整理以下 源代码网整理以下 Dim Cmd As OleDbCommand 软件开发网 www.mscto.com 源代码网整理以下 Cmd = New OleDbCommand( SQL, Conn ) 源代码网整理以下 Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter 源代码网整理以下 Adapter.SelectCommand = Cmd 源代码网整理以下 Dim ds As DataSet = new DataSet() 源代码网整理以下 Adapter.Fill(ds, "Users") 源代码网整理以下 Dim dt As DataTable = ds.Tables("Users") 源代码网整理以下 If dt.Rows.Count > 0 Then 源代码网整理以下 isok=true 源代码网整理以下 dim i,m as integer 源代码网整理以下 i=0 源代码网整理以下 m=3 源代码网整理以下 Label1.Text &= "user: " & userid & "<br>" 源代码网整理以下 Label1.Text &= "password: " & password & "<br>" 软件开发网 www.mscto.com 源代码网整理以下 Label1.Text &= "登录成功" & "<br>" 源代码网整理以下 session("ok") = "" & dt.Rows(i).Item(m) & "<br>" 源代码网整理以下 response.redirect ("first.aspx") 源代码网整理以下 Else 源代码网整理以下 isok=false 源代码网整理以下 Label1.Text &= "user: " & userid & "<br>" 源代码网整理以下 Label1.Text &= "password: " & password & "<br>" 源代码网整理以下 Label1.Text &= "登录失败" & "<br>" 源代码网整理以下 End If 源代码网整理以下 end if 源代码网整理以下 end if 源代码网整理以下 end if 软件开发网 www.mscto.com 源代码网整理以下 else 源代码网整理以下 exit sub 源代码网整理以下 end if 源代码网整理以下End sub 源代码网整理以下</script> 源代码网整理以下<Html> 源代码网整理以下<title>我的登录页面</title> 源代码网整理以下<Body BgColor="White"> 源代码网整理以下<wangmg:header id ="header1" runat="server" title="我的第一个Header"/> 源代码网整理以下<H3>登录页面<Hr></H3> 源代码网整理以下<form runat=server> 源代码网整理以下<Table BgColor="white" BorderColor="Black" 软件开发网 www.mscto.com 源代码网整理以下 Cellspacing="10"> 源代码网整理以下 <tr> 源代码网整理以下 <td>姓名:</td> 源代码网整理以下 <td><asp:TextBox id="Text1" runat="server"/> 源代码网整理以下 <asp:regularexpressionvalidator id="valid1" runat="server" controltovalidate="text1" 源代码网整理以下 validationexpression="[a-zA-Z0-9]{4,10}"> 软件开发网 www.mscto.com
源代码网整理以下 (请输入4-10位字符) 源代码网整理以下 </asp:regularexpressionvalidator><p> 源代码网整理以下 </td> 软件开发网 www.mscto.com 源代码网整理以下 </tr> 源代码网整理以下 <tr> 源代码网整理以下 <td>密码:</td> 源代码网整理以下 <td><asp:TextBox id="Text2" TextMode="Password" runat="server"/> 源代码网整理以下 <asp:regularexpressionvalidator id="valid2" runat="server" controltovalidate="text2" 源代码网整理以下 validationexpression="[a-zA-Z0-9]{4,8}"> 源代码网整理以下 (请输入4-8位字符) 源代码网整理以下 </asp:regularexpressionvalidator><p> 源代码网整理以下 </td> 源代码网整理以下 </tr> 源代码网整理以下 <tr> 软件开发网 www.mscto.com 源代码网整理以下 <td></td> 源代码网整理以下 <td><asp:Button id="button1" Text="确定" runat="server" onclick="IsLoginOK"/></td> 源代码网整理以下 </tr> 软件开发网 www.mscto.com 源代码网整理以下</table> 源代码网整理以下</form> 源代码网整理以下<asp:Label id="Label1" runat="server"/> 源代码网整理以下<asp:Label id="Label2" runat="server"/> 软件开发网 www.mscto.com 源代码网整理以下<wangmg:footer id="footer1" runat="server"/> 源代码网整理以下</body> 软件开发网 www.mscto.com
源代码网整理以下</html> 源代码网整理以下Header.ascx 源代码网整理以下public title as string 源代码网整理以下sub page_load(sender as object,e as eventargs) 源代码网整理以下label1.text=title 源代码网整理以下label2.text=cstr(filedatetime(server.mappath(request.filepath))) 源代码网整理以下end sub 源代码网整理以下</script> 源代码网整理以下<Table border="1" cellpadding="2" cellspacing="0" 源代码网整理以下 width="100%" bgcolor="#AAAADD"> 源代码网整理以下 <tr> 软件开发网 www.mscto.com 源代码网整理以下 <td align="center"><font size="4"> 源代码网整理以下 <B><asp:Label id="Label1" runat="server"/> 软件开发网 www.mscto.com 源代码网整理以下 </B></font> 源代码网整理以下 </td> 源代码网整理以下 </tr> 源代码网整理以下</Table> 源代码网整理以下 源代码网整理以下<Div Align="right"><Address><Font Size="-1"> 源代码网整理以下<asp:Label id="Label2" runat="server"/> 源代码网整理以下</Font></Address></Div> 源代码网整理以下</H2> 源代码网整理以下footer.ascx 源代码网整理以下<div align="right"> 源代码网整理以下<hr> 源代码网整理以下<a href="http://asp.6to23.com/musclecn" target="_top"> 软件开发网 www.mscto.com 源代码网整理以下学习asp.net找我</a> 软件开发网 www.mscto.com 源代码网整理以下</div> 源代码网整理以下这就是这个登录页面简单教程。 源代码网推荐 源代码网供稿. |
