我用vs2010做asp.net 写以下代码
后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 zty
{
    public partial class Login : System.Web.UI.Page
    {
        SqlConnection Conn = null;
        SqlCommand Comm = null;
        SqlDataAdapter Myadapter = null;
        DataSet Myds = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Session.Clear();
            }
            dl.Attributes.Add("onmouseover", "this.src='../images/bn_2.gif'");
            dl.Attributes.Add("onmouseout", "this.src='../images/bn_1.gif'");  
        }        protected void dl_Click(object sender, ImageClickEventArgs e)
        {
            Conn = new SqlConnection((string)Application["sql_zty"]);
            Conn.Open();
            string xm = Projectname.Text.ToString().Trim();
            string zh = Username.Text.ToString().Trim();
            string mm = password.Text.ToString().Trim();
            string sql_str = "";
            if (zh == "")
            {
                Response.Write("<script>alert('请输入登陆帐号!');history.back();</script>");
                Response.End();
            }
            else if (mm == "")
            {
                Response.Write("<script>alert('请输入登陆密码!');history.back();</script>");
                Response.End();
            }
            else if (xm != "")
            {
                sql_str = "select * from Login where Account='" + zh + "' and Name='" + xm + "'";
                Myadapter = new SqlDataAdapter(sql_str, Conn);
                Myds = new DataSet();
                Myadapter.Fill(Myds, "Login");
                if (Myds.Tables["Login"].Rows.Count <= 0)
                {
                    Response.Write("<script>alert('您还没有注册帐号或未参加该项目!');history.back();</script>");
                }
                else
                {
                    string pass = Myds.Tables["Login"].Rows[0]["password"].ToString().Trim();
                    string projectstrat = Myds.Tables["Login"].Rows[0]["status"].ToString().Trim();
                    string userstrat = Myds.Tables["Login"].Rows[0]["userstatus"].ToString().Trim();
                    string Project = Myds.Tables["Login"].Rows[0]["Projectstatus"].ToString().Trim();
                    if (pass != mm)
                    {
                        Response.Write("<script>alert('用户密码输入错误!');history.back();</script>");
                        Response.End();
                    }
                    else if (projectstrat == "0")
                    {
                        Response.Write("<script>alert('客服还未审核该项目!');history.back();</script>");
                        Response.End();
                    }
                    else if (projectstrat == "2")
                    {
                        string projectReason = Myds.Tables["Login"].Rows[0]["Reason"].ToString().Trim();
                        ClientScript.RegisterStartupScript(this.GetType(), "该项目的审核未被通过!", "<script language='javascript' >alert('因" + projectReason + "的原因,网站管理人员未通过该项目的审核!');</script>");
                    }
                    else if (userstrat == "0")
                    {
                        Response.Write("<script>alert('您加入该项目的申请还未被项目创建人审核!');history.back();</script>");
                        Response.End();
                    }
                    else if (userstrat == "2")
                    {
                        string userReason = Myds.Tables["Login"].Rows[0]["userReason"].ToString().Trim();
                        ClientScript.RegisterStartupScript(this.GetType(), "您加入该项目的审核未被通过!", "<script language='javascript' >alert('因" + userReason + "的原因,项目创建者未通过该项目的审核!');</script>");
                    }
                    else if (userstrat == "3")
                    {
                        string stopReason = Myds.Tables["Login"].Rows[0]["stop"].ToString().Trim();
                        string stoptime = Myds.Tables["Login"].Rows[0]["Enddate"].ToString().Trim();
                        ClientScript.RegisterStartupScript(this.GetType(), "您已经被踢出该项目!", "<script language='javascript' >alert('因" + stopReason + "的原因,您已经于" + stoptime + "被项目创建者踢出该项目!');</script>");
                    }
                    else if (userstrat == "4")
                    {
                        string endtime = Myds.Tables["Login"].Rows[0]["Enddate"].ToString().Trim();
                        ClientScript.RegisterStartupScript(this.GetType(), "您已经退出该项目!", "<script language='javascript' >alert(您已经于" + endtime + "退出该项目!');</script>");
                    }
                    else if (Project == "1")
                    {
                        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "友情提示!", "confirm('该项目已结束,您确认要进入该项目吗?')", true);
                        string name = Myds.Tables["Login"].Rows[0]["username"].ToString().Trim();
                        string userid = Myds.Tables["Login"].Rows[0]["userid"].ToString().Trim();
                        string projectname = Myds.Tables["Login"].Rows[0]["name"].ToString().Trim();
                        string projectid = Myds.Tables["Login"].Rows[0]["userid"].ToString().Trim();
                        string adds = Myds.Tables["Login"].Rows[0]["adds"].ToString().Trim();
                        Session["username"] = name;
                        Session["userid"] = userid;
                        Session["name"] = projectname;
                        Session["userid"] = projectid;
                        Session["adds"] = adds;
                        Response.Redirect("Manage/index.aspx");
                    }
                    else
                    {
                        string name = Myds.Tables["Login"].Rows[0]["username"].ToString().Trim();
                        string userid = Myds.Tables["Login"].Rows[0]["userid"].ToString().Trim();
                        string projectname = Myds.Tables["Login"].Rows[0]["name"].ToString().Trim();
                        string projectid = Myds.Tables["Login"].Rows[0]["userid"].ToString().Trim();
                        string adds = Myds.Tables["Login"].Rows[0]["adds"].ToString().Trim();
                        Session["username"] = name;
                        Session["userid"] = userid;
                        Session["name"] = projectname;
                        Session["userid"] = projectid;
                        Session["adds"] = adds;
                        Response.Redirect("Manage/index.aspx");
                    }
                }
            }
            else
            {
                wxm.Visible = true;
            }
                }        protected void xm_yes_Click(object sender, EventArgs e)
        {
            wxm.Visible = false;
            Conn = new SqlConnection((string)Application["sql_zty"]);
            Conn.Open();
            string xm = Projectname.Text.ToString().Trim();
            string zh = Username.Text.ToString().Trim();
            string mm = password.Text.ToString().Trim();            
            string sql_str = "";
            sql_str = "select * from Users where Account='" + zh + "'";
            Myadapter = new SqlDataAdapter(sql_str, Conn);
            Myds = new DataSet();
            Myadapter.Fill(Myds, "Users");
            if (Myds.Tables["Users"].Rows.Count <= 0)
            {
                Response.Write("<script>alert('当前用户不存在!');history.back();</script>");
            }
            else
            {
                string upass = Myds.Tables["users"].Rows[0]["password"].ToString().Trim();
                if (upass != mm)
                {
                    Response.Write("<script>alert('用户密码输入错误!');history.back();</script>");
                    Response.End();                    
                }
                else
                {
                    string name = Myds.Tables["users"].Rows[0]["name"].ToString().Trim();
                    string userid = Myds.Tables["users"].Rows[0]["id"].ToString().Trim();
                    Session["name"] = name;
                    Session["userid"] = userid;
                    Response.Redirect("Manage/index.aspx");
                }            }
            Comm.Dispose();
            Conn.Close();
            Conn.Dispose();
        }        protected void xm_no_Click(object sender, EventArgs e)
        {
            wxm.Visible = false;
        }
            }
        }我要达到的目的是框xm里有没有内容都可以登入 但会跳出个div提示框是否确定xm为空 是的话就执行下面的是的话就登陆 否的话就div提示框隐藏 如果xm不为空则直接登陆但现在实际情况是这样的:我xm框里不输入东西 在zh和mm框里输上了,点登陆 跳出刚才那个div框 按框里的否的话是正常的,按是的话 他跳出密码错误提示(其实密码是正确的),密码错误提示上的确定点了以后 跳回登陆窗口 发现div提示框没隐藏(我明明写过隐藏的),然后在密码框里填入密码,再按div提示框上的是才可以正常登陆
经过证实那个跳出的密码错误提示是那个叫xm_yes的按钮里的

解决方案 »

  1.   

    急谢谢前<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="zty.Login" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>找图易——登录</title>
        <link href="css.css" rel="stylesheet" type="text/css" />
    <script type="text/JavaScript">    function MM_preloadImages() { //v3.0
            var d = document; if (d.images) {
                if (!d.MM_p) d.MM_p = new Array();
                var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
                    if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
            }
        }    function MM_findObj(n, d) { //v4.01
            var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
                d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
            }
            if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
            for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
            if (!x && d.getElementById) x = d.getElementById(n); return x;
        }    function MM_swapImgRestore() { //v3.0
            var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
        }    function MM_swapImage() { //v3.0
            var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
                if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
        }</script>
    <style type="text/css">.STYLE1 {color: #FFFFFF}</style>
    </head><body onload="MM_preloadImages('images/enter_2.jpg','images/bn_2.gif')" >
    <form runat="server">
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
      <tr>
        <td height="150" align="center" valign="bottom" background="images/lt_1.gif"><img src="images/logo.jpg" width="167" height="60" alt="" /></td>
      </tr>
      <tr>
        <td background="images/tt.jpg"><img src="images/tt.jpg" width="35" height="17" alt="" /></td>
      </tr>
      <tr>
        <td height="200" align="center"><table width="270" border="0" cellspacing="0" cellpadding="0" >
          <tr>
            <td height="30" bgcolor="#141414"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><img src="images/information.png" width="16" height="16" alt="" /></td>
                  <td><span class="biao">新用户请点击<a href="#" class="b">立即注册</a> 老用户请点击<a href="#" class="b">忘记密码</a></span></td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>         
                <td width="40%"><div align="right" class="biao">项目名Projectname</div> <div style="position:absolute; z-index: 2000; margin:0 auto;" id="wxm" runat="server" visible="false" width="100%" height="100%" align="center">
    <table cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td height="20px" width="200px" bgcolor="#0066CC" align="left">提示</td>
    </tr>
    <tr>
    <td height="60px" width="200px" bgcolor="#CCCCCC"> 您确定不登陆项目吗?</td>
    </tr>
    <tr>
    <td height="20px" width="200px" bgcolor="#CCCCCC"><asp:Button ID="xm_yes" Text="是" runat="server" OnClick="xm_yes_Click" />&nbsp;&nbsp;&nbsp; <asp:Button ID="xm_no" Text="否" runat="server" OnClick="xm_no_Click" /></td>
    </tr>
    </table>
    </div></td>
                <td width="60%" height="40" align="center">
                
                  <asp:TextBox width="150px" maxlength="20" id="Projectname" runat="server"></asp:TextBox>              
                   </td>
              </tr>
              <tr>
                <td><div align="right" class="biao">用户名Username</div></td>
                <td height="40" align="center">
             
                   <asp:TextBox width="150px" maxlength="20" id="Username" runat="server"></asp:TextBox>   
                   </td>
              </tr>
              <tr>
                <td><div align="right"><span class="biao">密码password</span></div></td>
                <td height="40" align="center">
                 
                  <asp:TextBox width="150px" maxlength="20" id="password" runat="server" TextMode="Password"></asp:TextBox>   
                  </td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="40"><div align="center">
              <table width="58%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="60%"><asp:ImageButton  Width="80px" Height="26px" runat="server" ID="dl"  ImageUrl="~/images/bn_1.gif" OnClick="dl_Click" />            
                  </td>
                  <td width="40%"><a href="#" class="biao">游客访问</a></td>
                </tr>
              </table>
            </div></td>
          </tr>
        </table></td>
      </tr>
    </table>
    </form>
    </body>
    </html>
      

  2.   

    Users 和user一样吗!您自己写错了