设计如图:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
用户名:<asp:TextBox ID="usernmae" runat="server"></asp:TextBox>
<br />
密 码:<asp:TextBox ID="password" runat="server" TextMode="Password"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="登陆" onclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
双击登陆按钮打开后置cs代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
Member member;
if (this.usernmae.Text.Trim().Length == 0)
{
Response.Write("<script>alert('请输入用户名')</script>");
}
else if(this.password.Text.Trim().Length == 0)
{
Response.Write("<script>alert('请输入密码')</script>");
}
else if (MemberManage.Login(this.usernmae.Text, this.password.Text, out member))
{
Session["Member"] = member;
Response.Redirect("default.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码错误!')</script>");
}
}