北大青鸟.net学习之三--登陆验证简单代码
要求:输入用户名和密码,给定登录用户名和密码,登录成功或登陆失败报告,
清空时数据为空,关闭,退出窗口:
代码:
<%@ Page language="c#" Codebehind="bdqnyz.aspx.cs" AutoEventWireup="false" Inherits="bdqn.bdqnyz" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>bdqnyz</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 96px" runat="server"
BackColor="#E0E0E0">用户名:</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 128px" runat="server"
BackColor="#E0E0E0" Width="65px">密 码:</asp:Label>
<asp:TextBox id="UserName" style="Z-INDEX: 103; LEFT: 264px; POSITION: absolute; TOP: 96px" runat="server"></asp:TextBox>
<asp:TextBox id="UserPwd" style="Z-INDEX: 104; LEFT: 264px; POSITION: absolute; TOP: 128px" runat="server"></asp:TextBox>
<asp:Button id="Submit" style="Z-INDEX: 105; LEFT: 208px; POSITION: absolute; TOP: 160px" runat="server"
Text="提交"></asp:Button>
<asp:Button id="Cancel" style="Z-INDEX: 106; LEFT: 280px; POSITION: absolute; TOP: 160px" runat="server"
Text="取消"></asp:Button>
<asp:Button id="Close" style="Z-INDEX: 107; LEFT: 352px; POSITION: absolute; TOP: 160px" runat="server"
Text="关闭"></asp:Button>
<asp:Label id="Label3" style="Z-INDEX: 108; LEFT: 296px; POSITION: absolute; TOP: 216px" runat="server"
BackColor="Red">登录信息</asp:Label>
</form>
</body>
</HTML>
代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
![]()
namespace bdqn
{
/// <summary>
/// bdqnyz 的摘要说明。
/// </summary>
public class bdqnyz : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.TextBox UserPwd;
protected System.Web.UI.WebControls.Button Submit;
protected System.Web.UI.WebControls.Button Cancel;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button Close;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
![]()
Web 窗体设计器生成的代码
![]()
private void Submit_Click(object sender, System.EventArgs e)
{
if(this.UserName.Text=="yyb" && this.UserPwd.Text=="yyb")
{
this.Label3.Text="登录成功!";
}
else
{
this.Label3.Text="登录失败!";
}
}
![]()
private void Cancel_Click(object sender, System.EventArgs e)
{
this.UserName.Text="";
this.UserPwd.Text="";
}
![]()
private void Close_Click(object sender, System.EventArgs e)
{
Response.Write("<script>window.close()</script>");
}
}
}
清空时数据为空,关闭,退出窗口:
代码:
<%@ Page language="c#" Codebehind="bdqnyz.aspx.cs" AutoEventWireup="false" Inherits="bdqn.bdqnyz" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>bdqnyz</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 96px" runat="server"
BackColor="#E0E0E0">用户名:</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 128px" runat="server"
BackColor="#E0E0E0" Width="65px">密 码:</asp:Label>
<asp:TextBox id="UserName" style="Z-INDEX: 103; LEFT: 264px; POSITION: absolute; TOP: 96px" runat="server"></asp:TextBox>
<asp:TextBox id="UserPwd" style="Z-INDEX: 104; LEFT: 264px; POSITION: absolute; TOP: 128px" runat="server"></asp:TextBox>
<asp:Button id="Submit" style="Z-INDEX: 105; LEFT: 208px; POSITION: absolute; TOP: 160px" runat="server"
Text="提交"></asp:Button>
<asp:Button id="Cancel" style="Z-INDEX: 106; LEFT: 280px; POSITION: absolute; TOP: 160px" runat="server"
Text="取消"></asp:Button>
<asp:Button id="Close" style="Z-INDEX: 107; LEFT: 352px; POSITION: absolute; TOP: 160px" runat="server"
Text="关闭"></asp:Button>
<asp:Label id="Label3" style="Z-INDEX: 108; LEFT: 296px; POSITION: absolute; TOP: 216px" runat="server"
BackColor="Red">登录信息</asp:Label>
</form>
</body>
</HTML>
代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace bdqn
{
/// <summary>
/// bdqnyz 的摘要说明。
/// </summary>
public class bdqnyz : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.TextBox UserPwd;
protected System.Web.UI.WebControls.Button Submit;
protected System.Web.UI.WebControls.Button Cancel;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button Close;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
Web 窗体设计器生成的代码
private void Submit_Click(object sender, System.EventArgs e)
{
if(this.UserName.Text=="yyb" && this.UserPwd.Text=="yyb")
{
this.Label3.Text="登录成功!";
}
else
{
this.Label3.Text="登录失败!";
}
}
private void Cancel_Click(object sender, System.EventArgs e)
{
this.UserName.Text="";
this.UserPwd.Text="";
}
private void Close_Click(object sender, System.EventArgs e)
{
Response.Write("<script>window.close()</script>");
}
}
}


浙公网安备 33010602011771号