管理员登录设计(第7节) |
|
本文标签:ASP.NET,管理员登录 本文实现管理员登录效果,当用户名和密码正确时,弹出登录成功提示,否则弹出用户名或密码错误提示 。 定义
小提示:在插入表格的时候,应注意表格的大小、布局、边框、背景的设置,提前做好准备,可以节省接下来的工作;第二点就是区分image与imagebutton 。 学习任务三 实现登录界面的验证
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SnCode.Create();
}
}
步骤5:双击Login按钮,在adminlogin.aspx.cs代码页添加如下代码:
public partial class admin_adminlogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SnCode.Create();
}
}
protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
{
if (SnCode.CheckSN(TextBox3.Text.Trim()))
{
String username = TextBox1.Text;
String userpwd = TextBox2.Text;
users user1 = null;
user1 = new users();
user1.Admin = username;
user1.Pwd = userpwd;
DataSet ds1 = new userschuli().adminlogin(user1);
DataTable dt = ds1.Tables[0];
if (dt.Rows.Count > 0)
{
Response.Write("<script>alert(用户名和密码正确!);</script>");
}
else
{
Response.Write("<script>alert(用户名或密码不正确!);</script>");
}
}
else
{
Response.Write("<script>alert(验证码错误!);</script>");
}
}
protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
步骤6:运行调试代码,当用户名和密码正确以及验证码正确时,弹出登录成功提示框,否则弹出用户名或密码错误提示框 。 运行效果图:
总结 希望以上内容可以对大家的学习有所帮助 。 |