要求:用户名和密码从数据库中读取,如正确,提示“登录成功”;如错误,给出错误提示。

解决方案 »

  1.   

    点击登录按钮发送Ajax请求到后台查询数据库,后台判断登录是否成功再将状态返回给前台,很简单的。
    当然你直接用服务器控件的按钮,在Click事件里写代码也可以,但是这样做会刷新界面。
      

  2.   

    服务器有很多 验证控件 或者 用ajax实现 或者你可以 给登录按钮加上事件在后台编写代码,把用户输入的 内容取出 和数据库进行比较,正确或者错误 弹框 
      

  3.   

    <!--登录的div开始-->
            <div class="divlogin">
                <table>
                    <tr>
                        <td>
                            用户名:
                        </td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            密 码:
                        </td>
                        <td>
                            <asp:TextBox ID="txtPass" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">
                            <asp:Label ID="labPrompt" runat="server" Text="请输入用户名、密码" ForeColor="Red"></asp:Label>
                            
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">
                            <asp:Button ID="btnSub" runat="server" Text="提交" onclick="btnSub_Click" />
                            <asp:Button ID="btnCel" runat="server" Text="取消" onclick="btnCel_Click" />                        
                        </td>
                    </tr>
                </table>
            </div>
            <!--登录的div结束-->
      

  4.   

      protected void btnSubmit_Click(object sender, EventArgs e)
        {
           if (txtName.Text.Trim() == "" || txtPass.Text.Trim() == "")
            {
                return;
            }
                   string sSQL = "";
            sSQL += " select count(*) cnt  from UserInfo ";
            sSQL += " where username='" + Comm.SQLInjection.CheckSQLStr(txtName.Text.Trim()) + "' and pass='" + Comm.SQLInjection.CheckSQLStr(txtPass.Text.Trim()) + "' ";
           
            DataSet ds = Comm.SqlHelper.ExecuteDataSet(Comm.SqlHelper.ConnectionString, CommandType.Text, sSQL);
           
            if (Convert.ToInt32(ds.Tables[0].Rows[0][0]) <= 0)
            {            message.Visible = true;
                message.Text = "用户名或命名错误,请重试";
                return;
            }
            else
            {   
              Response.Write("<script>alert('登录成功)</script>");           Response.Redirect("转到成功后的页面.aspx");
             }
    }
      

  5.   


    这老师,教神马呢?有些东西必须让老师负责的!哪怕是XXX鸟老师也不能这个样子啊。
      

  6.   

    大神,还什么数据库啊,直接写死用户名和密码呗,拖两文本框,一个按钮,按钮的点击事件写上这个。哈哈哈。。
    if(textbox1.Text=="用户名"&&textbox2.Text=="密码")
    {
        Response.Write("alert('成功')");
    }
    else
    {
        Response.Write("alert('失败')");
    }
      

  7.   

    创建完数据库,连接数据库,把用户名和密码框获得的数据(不需要全部套用)与数据库的比较一下就是了,如果用asp.net的话还有直接的验证控件,用不用看你的了,初学的话还是用吧