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;
using System.Data.SqlClient;
namespace index
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
/// 

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button topost;
protected System.Web.UI.WebControls.TextBox userpwd;
protected System.Web.UI.WebControls.TextBox username;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlCommand sqlCommand1;

private void Page_Load(object sender, System.EventArgs e)


}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.topost.Click += new System.EventHandler(this.topost_Click);
this.Load += new System.EventHandler(this.Page_Load); }
          #endregion
private void topost_Click(object sender, System.EventArgs e)
{
SqlConnection Conn=new SqlConnection("server=soft.;database=employee;user id=sa;password=123;"); SqlCommand rs=new SqlCommand("select * from ADMIN where ID=1",Conn); 
Conn.Open();

SqlDataReader dr=rs.ExecuteReader();                          this.Response.Write(rs["USERNAME"]); this.Response.End();//c#中这样不能从数据库中读取数据吗? if (username.Text=rs["USERNAME"] && userpwd.Text=rs["USERPWD"])
{
this.Response.Redirect("login.aspx");
}
else
{
   this.Response.Write("对不起,您是非法用户请重新登陆!");
//如果我想在让它弹出个消息框,javascript应该怎么写呢?刚接触c#,不懂就问,希望看到此帖的朋友给我的帮助,谢谢!
}
    
}
}
}

解决方案 »

  1.   

    this.Response.Write("<script>alert('对不起,您是非法用户请重新登陆!')</script>");
      

  2.   

    Response.Write("<script>alert('对不起,您是非法用户请重新登陆!')</script>");
      

  3.   

    right,再帮你解释一下
    楼主写的代码都是在server段运行的,如果想弹出对话框则需要在客户端运行的代码,如
    jscript, vbscript.
    哲别老兄的代码
    this.Response.Write("<script>alert('对不起,您是非法用户请重新登陆!')</script>");
    旨在给client端返回一段jscript代码,客户端load完页面之后将自动执行此段script,弹出对话框
      

  4.   

    兄弟,他们上面写的
    this.Response.Write("<script>alert('对不起,您是非法用户请重新登陆!')</script>");
    虽然可以用,但是不太好的。不好的地方,你试了就知道了
    建议你用
    Page.RegisterStartupScript("abc","<script>alert('对不起,您是非法用户请重新登陆!);</script>");
      

  5.   

    Response.Write("<script>alert('对不起,您是非法用户请重新登陆!');window.location.href='因登录失败而想返回的页面'</script>");
    return;//以上的考虑比较周到
      

  6.   

    this.response.write("<script language='javascript'>alert("对不起,您是非法用户请重新登陆!")</script>")
      

  7.   

    还是用zhouxiaochenchina的好本人意见~~~!!!!!