<%@ Page language="c#" Codebehind="Home.aspx.cs" AutoEventWireup="false" Inherits="question.member" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>请先登陆</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" style="Z-INDEX: 103; LEFT: 168px; POSITION: absolute; TOP: 80px" runat="server"
Width="89px" Height="8px">用户ID</asp:label>
<asp:label id="Label2" style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP: 128px" runat="server"
Width="88px" Height="16px">密码</asp:label>
<asp:button id="Button1" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 184px" runat="server"
Width="104px" Text="我是教师"></asp:button>;
<asp:textbox id="TextBox1" style="Z-INDEX: 104; LEFT: 304px; POSITION: absolute; TOP: 80px" runat="server"
Height="16px"></asp:textbox>
<asp:textbox id="TextBox2" style="Z-INDEX: 105; LEFT: 304px; POSITION: absolute; TOP: 128px"
runat="server" Height="16px" TextMode="Password"></asp:textbox>
<asp:button id="Button2" style="Z-INDEX: 106; LEFT: 344px; POSITION: absolute; TOP: 184px" runat="server"
Width="105px" Text="我是管理员"></asp:button></form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 question
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class member: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;
public string idnum;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}private void Button1_Click(object sender, System.EventArgs e)
{
string pass;
idnum=TextBox1.Text;
pass=TextBox2.Text;
if(idnum==null || pass==null)
Response.Write("对不起,请检查用户名和密码输入;");
else
{
string ConnString = "server=local;initial=题库;UID=sa;PWD=";
string CommString="SELECT * FROM TEACHER WHERE ID=idnum AND PASSWORD=pass";
SqlConnection SqlConn = new SqlConnection(ConnString);
SqlCommand com=new SqlCommand(CommString,SqlConn);
SqlDataReader dr;
SqlConn.Open();
dr=com.ExecuteReader();
if(dr.Read())
{
Session["userid"]=idnum;
Response.Redirect("teacherlogin.aspx");
}
else
Response.Write("对不起,帐号密码不对,请确定输入;");
SqlConn.Close();
}
}private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);}private void Button2_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text=="" || TextBox2.Text=="")
Response.Write("对不起,请检查用户名和密码输入;");
Response.Redirect("adminlogin.aspx");
}
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>请先登陆</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" style="Z-INDEX: 103; LEFT: 168px; POSITION: absolute; TOP: 80px" runat="server"
Width="89px" Height="8px">用户ID</asp:label>
<asp:label id="Label2" style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP: 128px" runat="server"
Width="88px" Height="16px">密码</asp:label>
<asp:button id="Button1" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 184px" runat="server"
Width="104px" Text="我是教师"></asp:button>;
<asp:textbox id="TextBox1" style="Z-INDEX: 104; LEFT: 304px; POSITION: absolute; TOP: 80px" runat="server"
Height="16px"></asp:textbox>
<asp:textbox id="TextBox2" style="Z-INDEX: 105; LEFT: 304px; POSITION: absolute; TOP: 128px"
runat="server" Height="16px" TextMode="Password"></asp:textbox>
<asp:button id="Button2" style="Z-INDEX: 106; LEFT: 344px; POSITION: absolute; TOP: 184px" runat="server"
Width="105px" Text="我是管理员"></asp:button></form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 question
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class member: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;
public string idnum;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}private void Button1_Click(object sender, System.EventArgs e)
{
string pass;
idnum=TextBox1.Text;
pass=TextBox2.Text;
if(idnum==null || pass==null)
Response.Write("对不起,请检查用户名和密码输入;");
else
{
string ConnString = "server=local;initial=题库;UID=sa;PWD=";
string CommString="SELECT * FROM TEACHER WHERE ID=idnum AND PASSWORD=pass";
SqlConnection SqlConn = new SqlConnection(ConnString);
SqlCommand com=new SqlCommand(CommString,SqlConn);
SqlDataReader dr;
SqlConn.Open();
dr=com.ExecuteReader();
if(dr.Read())
{
Session["userid"]=idnum;
Response.Redirect("teacherlogin.aspx");
}
else
Response.Write("对不起,帐号密码不对,请确定输入;");
SqlConn.Close();
}
}private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);}private void Button2_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text=="" || TextBox2.Text=="")
Response.Write("对不起,请检查用户名和密码输入;");
Response.Redirect("adminlogin.aspx");
}
}
}
{
Button1.Click += new EventHandler(this.Button1_Click);
} protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("WJS");
}
2005中没有这个了
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 question
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class member: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
InitializeComponent(); // 在此处放置用户代码以初始化页面
} private void Button1_Click(object sender, System.EventArgs e)
{
string idnum;
string pass;
idnum=TextBox1.Text.Trim();
pass=TextBox2.Text.Trim();
if(idnum.Length==0 || pass.Length==0)
Label3.Text="对不起,请检查用户名和密码输入";
else {}
} private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click); } private void Button2_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text=="" || TextBox2.Text=="")
Response.Write("对不起,请检查用户名和密码输入;");
Response.Redirect("adminlogin.aspx");
}
}
}修改成这样也不行,诸位谢谢帮忙啊
这样试试