<%@ 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");
}
}
}

解决方案 »

  1.   

    private void Button2_Click(object sender, System.EventArgs e)
    {
    if(TextBox1.Text=="" || TextBox2.Text=="")
    Response.Write("<script>alert('对不起,请检查用户名和密码输入');window.location.href='adminlogin.aspx';</script>");
    }
      

  2.   

    Response.Write("对不起,请检查用户名和密码输入;");
    Response.Redirect("adminlogin.aspx");
    没什么问题,应该可以跳转的Response.Write("<script>alert('对不起,请检查用户名和密码输入');window.location.href='adminlogin.aspx';</script>");只是用Javascript而已建议LZ设置断点调试一下,看是否执行到
    Response.Write("对不起,请检查用户名和密码输入;");
    Response.Redirect("adminlogin.aspx");
      

  3.   

    我也遇到这个问题,不是程序没执行到的问题
    如果在一个Response.Write后加个return返回的话,那么就会显示提示框
    原因是程序一路执行下来到Response.Redirect("adminlogin.aspx")页面跳转期间没有障碍的话就不会显示中途的各种操作结果,而是直接实现页面跳转。
      

  4.   

    Button1应该可以执行吧
    Button没有被调用,在
    private void InitializeComponent()
    {
    this.Button1.Click += new System.EventHandler(this.Button1_Click);}
    加一句
    this.Button2.Click += new System.EventHandler(this.Button2_Click);才行
      

  5.   

    Response.Write("<script language=javascript>alert('对不起,帐号密码不对,请确定输入');</script>");
      

  6.   

    呵呵.你是不是想等它提示个对话框,然后再跳转呢。
    这个基本我是没实现过。再说前面几楼说的也行嘛。
    Response.Write("<script>alert('对不起,请检查用户名和密码输入');window.location.href='adminlogin.aspx';</script>");
    一样可以实现效果的。
    我一般都用这个的