<%@ 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");
}
}
}
解决方案 »
- 关于编写的 windows 服务
- 关于拉姆达表达式的疑问
- 【求助】Winform里面数据加密之后的异常、数据无效
- 谁有C#常用函数模式,就像if (MessageBox.Show("确实要退出系统吗?", "系统", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)之类的
- 在aspx.cs文件里面怎么调用在aspx文件中定义的javascript编写的函数
- 各位请帮忙,我是刚开始做window Form ,请问我首先打开一个
- c#在winform里面实现针式打印机打印发票
- ===当系统中存在多张网卡,我通过网上流行的函数得到的IP地址表,如何确定哪个地址是当前的使用的IP===
- 高手请教:怎么将字符串转化为二进制的BitArray?
- 如何让 vs.net 运行的更快
- Gridview中加入了删除提示框,如何知道用户按的是确定和取消呢?
- Socket通信,在Windows 2000下没问题,在2003下遇到问题。
{
if(TextBox1.Text=="" || TextBox2.Text=="")
Response.Write("<script>alert('对不起,请检查用户名和密码输入');window.location.href='adminlogin.aspx';</script>");
}
Response.Redirect("adminlogin.aspx");
没什么问题,应该可以跳转的Response.Write("<script>alert('对不起,请检查用户名和密码输入');window.location.href='adminlogin.aspx';</script>");只是用Javascript而已建议LZ设置断点调试一下,看是否执行到
Response.Write("对不起,请检查用户名和密码输入;");
Response.Redirect("adminlogin.aspx");
如果在一个Response.Write后加个return返回的话,那么就会显示提示框
原因是程序一路执行下来到Response.Redirect("adminlogin.aspx")页面跳转期间没有障碍的话就不会显示中途的各种操作结果,而是直接实现页面跳转。
Button没有被调用,在
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);}
加一句
this.Button2.Click += new System.EventHandler(this.Button2_Click);才行
这个基本我是没实现过。再说前面几楼说的也行嘛。
Response.Write("<script>alert('对不起,请检查用户名和密码输入');window.location.href='adminlogin.aspx';</script>");
一样可以实现效果的。
我一般都用这个的