用户名/密码/验证码/显示验证码 控件的属性设置,可以通过前台代码实现,也可以在“控件属性”对话框中的设置实现,本页中使用的控件属性设置请参见如下代码: http://www.paper51.com
<table> http://www.paper51.com
<tr> copyright paper51.com <td align="right" style="width: 443px; height:233px"> 内容来自www.paper51.com
</td> copyright paper51.com
<td style="width: 121px; height: 233px"> paper51.com </td> 内容来自www.paper51.com <td align="left" style="width: 114px; height:233px"> http://www.paper51.com
</td> http://www.paper51.com </tr> 内容来自论文无忧网 www.paper51.com <tr> http://www.paper51.com <td align="right" style="width: 443px"> copyright paper51.com <ASP.NET:Label ID="labUserName" runat="server"Font-Size="9pt"Text="用户名"></ASP.NET:Label></td> copyright paper51.com
<td style="width: 121px"> paper51.com <ASP.NET:TextBox ID="txtUserName" runat="server"Width="120px"></ASP.NET:TextBox></td> http://www.paper51.com <td align="left" style="width: 114px"> paper51.com
<ASP.NET:RequiredFieldValidator ID="RequiredFieldValidator2"runat="server" ControlToValidate="txtPwd"Display="Dynamic" ErrorMessage="请输入密码!"></ASP.NET:RequiredFieldValidator> paper51.com
<ASP.NET:RequiredFieldValidatorID="RequiredFieldValidator1" runat="server"ControlToValidate="txtUserName" Display="Dynamic"ErrorMessage="请输入用户名!"></ASP.NET:RequiredFieldValidator></td> http://www.paper51.com
</tr> 内容来自www.paper51.com <tr> paper51.com <td align="right" style="width: 443px; height:37px"> 内容来自论文无忧网 www.paper51.com <ASP.NET:Label ID="labPwd" runat="server"Font-Size="9pt"Text="密码"></ASP.NET:Label></td> copyright paper51.com <td style="width: 121px; height: 37px"> copyright paper51.com <ASP.NET:TextBox ID="txtPwd" runat="server"TextMode="Password" Width="120px"></ASP.NET:TextBox></td> paper51.com <td align="left" style="width: 114px; height:37px"> 内容来自www.paper51.com </td> paper51.com </tr> http://www.paper51.com
<tr> 内容来自www.paper51.com <td align="right" style="width: 443px; height:19px"> 内容来自www.paper51.com <ASP.NET:Label ID="Label4" runat="server"Font-Size="9pt"Text="验证码"></ASP.NET:Label></td> copyright paper51.com <td style="width: 121px; height: 19px"> 内容来自www.paper51.com
<ASP.NET:TextBox ID="txtValidate" runat="server"Width="76px"></ASP.NET:TextBox> copyright paper51.com <ASP.NET:Label ID="labValidate" runat="server"BackColor="#C0C0FF"ForeColor="Red" Text="Label"></ASP.NET:Label></td> 内容来自论文无忧网 www.paper51.com <td align="left" style="width: 114px; height:19px"> 内容来自论文无忧网 www.paper51.com
<ASP.NET:RequiredFieldValidatorID="RequiredFieldValidator3" runat="server"ControlToValidate="txtValidate" Display="Dynamic"ErrorMessage="请输入验证码!"></ASP.NET:RequiredFieldValidator></td> 内容来自www.paper51.com </tr> 内容来自论文无忧网 www.paper51.com <tr> 内容来自论文无忧网 www.paper51.com
<td align="right" style="width: 443px"> 内容来自论文无忧网 www.paper51.com <ASP.NET:CheckBoxList ID="cblAdminLog"runat="server" Font-Size="8pt"> http://www.paper51.com <ASP.NET:ListItem>管理员登陆</ASP.NET:ListItem> copyright paper51.com </ASP.NET:CheckBoxList></td> 内容来自论文无忧网 www.paper51.com <td style="width: 121px"> paper51.com <ASP.NET:Button ID="btnLogin" runat="server"Font-Size="9pt"Text="登录"OnClick="Button1_Click" /> copyright paper51.com
<ASP.NET:Button ID="btnZhunce" runat="server"CausesValidation="False" Font-Size="9pt" paper51.com
OnClick="Button2_Click" Text="注册" /> http://www.paper51.com <ASP.NET:Button ID="btnPwd" runat="server"CausesValidation="False" Font-Size="9pt" http://www.paper51.com OnClick="Button3_Click"Text="忘密" /></td> http://www.paper51.com <td rowspan="1" style="width: 114px"> paper51.com </td> http://www.paper51.com
</tr> http://www.paper51.com </table> 内容来自论文无忧网 www.paper51.com 2.后台功能代码 内容来自www.paper51.com 系统登录模块主要用于验证用户登录系统时输入的用户名、密码和验证码是否正确,在处理登录页面提交的数据时,首先会根据“管理员”复选框的值来判断是否登陆管理员页面,此功能代码首先if- else语句判断复选框CheckBoxList1控件是否被选中,如果被选中则执行核对用户名、密码和验证码而进入管理员页面,反之则会执行另一段代码,以验证非管理员登录信息,而进入学生考试页面,处理代码如下所示: 内容来自www.paper51.com using System; 内容来自www.paper51.com
using System.Data; http://www.paper51.com
using System.Configuration; 内容来自论文无忧网 www.paper51.com using System.Collections; paper51.com
using System.Web; paper51.com
using System.Web.Security; paper51.com using System.Web.UI; http://www.paper51.com
using System.Web.UI.WebControls; copyright paper51.com using System.Web.UI.WebControls.WebParts; http://www.paper51.com using System.Web.UI.HtmlControls; http://www.paper51.com using System.Data.SqlClient; paper51.com public partial class Default : System.Web.UI.Page paper51.com { 内容来自论文无忧网 www.paper51.com Datacon dataconn = new Datacon(); paper51.com protected void Page_Load(objectsender, EventArgs e) 内容来自www.paper51.com { 内容来自www.paper51.com Session["StuName"] = this.txtUserName.Text; paper51.com if (!IsPostBack) 内容来自www.paper51.com { 内容来自论文无忧网 www.paper51.com Random rnd = new Random(); 内容来自www.paper51.com //生成验证码 paper51.com this.labValidate.Text = rnd.Next(1000,9999).ToString(); copyright paper51.com } paper51.com
} http://www.paper51.com //==============================找回密码======================== 内容来自论文无忧网 www.paper51.com
protected voidButton3_Click(object sender, EventArgs e) http://www.paper51.com
{ http://www.paper51.com Page.Response.Redirect("InfoPwd.ASP.NETx"); http://www.paper51.com
} 内容来自论文无忧网 www.paper51.com //==============================新学生注册======================= copyright paper51.com protected voidButton2_Click(object sender, EventArgs e) 内容来自www.paper51.com { paper51.com Page.Response.Redirect("zhuce.ASP.NETx"); paper51.com } paper51.com //==============================登录按钮========================= 内容来自论文无忧网 www.paper51.com protected voidButton1_Click(object sender, EventArgs e) 内容来自www.paper51.com
{ http://www.paper51.com if (txtValidate.Text != labValidate.Text) 内容来自论文无忧网 www.paper51.com
{ http://www.paper51.com Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>"); http://www.paper51.com } copyright paper51.com else copyright paper51.com { 内容来自论文无忧网 www.paper51.com if (cblAdminLog.Items[0].Selected == true) paper51.com { paper51.com this.getcom(1); paper51.com } copyright paper51.com
else http://www.paper51.com { copyright paper51.com this.getcom(2); 内容来自www.paper51.com } 内容来自论文无忧网 www.paper51.com } copyright paper51.com
} 内容来自www.paper51.com
//=============================登录控制===================== 内容来自www.paper51.com private voidgetcom(int i) paper51.com { 内容来自www.paper51.com SqlConnection con = dataconn.getcon(); 内容来自论文无忧网 www.paper51.com con.Open(); 内容来自www.paper51.com
SqlCommand com=con.CreateCommand(); http://www.paper51.com switch (i) 内容来自www.paper51.com { 内容来自www.paper51.com case 1: copyright paper51.com com.CommandText = "select count(*) from tb_Administrator whereName='" + txtUserName.Text + "' and PWD='" + txtPwd.Text +"'"; 内容来自论文无忧网 www.paper51.com
int count1 = Convert.ToInt32(com.ExecuteScalar());//获取SQL语句的值 强制转换成数值类型 内容来自www.paper51.com
if (count1 > 0) 内容来自论文无忧网 www.paper51.com { copyright paper51.com Application["Name"]= txtUserName.Text;//成功 http://www.paper51.com Application["PWD"] = txtPwd.Text;//成功 paper51.com
Page.Response.Redirect("HouAdmin/admin.ASP.NETx"); 内容来自论文无忧网 www.paper51.com } 内容来自论文无忧网 www.paper51.com else 内容来自论文无忧网 www.paper51.com { copyright paper51.com
Response.Write("<scriptlanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>"); 内容来自www.paper51.com
return; 内容来自论文无忧网 www.paper51.com
} paper51.com
break; paper51.com case 2: http://www.paper51.com
com.CommandText = "select count(*) from tb_Student where ID='"+ txtUserName.Text + "' and PWD='" + txtPwd.Text + "'"; http://www.paper51.com
int count2 = Convert.ToInt32(com.ExecuteScalar()); 内容来自www.paper51.com if (count2 > 0) 内容来自论文无忧网 www.paper51.com { 内容来自论文无忧网 www.paper51.com Application["ID"] = txtUserName.Text; 内容来自www.paper51.com Application["PWD"] = txtPwd.Text; 内容来自论文无忧网 www.paper51.com Page.Response.Redirect("QianUser/zaixian_kaoshi.ASP.NETx"); copyright paper51.com
} http://www.paper51.com else http://www.paper51.com { paper51.com
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>"); copyright paper51.com return; 内容来自www.paper51.com } 内容来自www.paper51.com break; http://www.paper51.com } http://www.paper51.com con.Close(); 内容来自论文无忧网 www.paper51.com
} 内容来自论文无忧网 www.paper51.com
} http://www.paper51.com |