我做个前台登陆界面,可能有错啊,请教大家如何连接数据库对身份验证,正确进入main.aspx界面呢?数据库名NET,表名users。表的字段是login_id.password。
我的代码如下:
<%@ Page language="c#" %>
<script runat="server">
    protected void btnlogin_Click(object sender, EventArgs e)
    {   
    }
</script>
<HTML>
  <HEAD>
<TITLE></TITLE>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="" type="text/css" rel="stylesheet">
  </HEAD>
<BODY bgColor="#619bd8" leftMargin="0" topMargin="0" scroll="no">
<DIV align="center">
<CENTER>
<TABLE cellSpacing="0" cellPadding="0" width="0" border="0">
<TBODY>
<TR>
<TD vAlign="bottom" height="50" style="width: 260px"></TD>
</TR>
<TR>
<TD style="width: 260px">
<TABLE class="OfficeLogin" height="140" cellSpacing="0" cellPadding="0" width="100%" bgColor="gainsboro" border="0">
<TBODY>
<TR>
<TD style="height: 72px">
<TABLE height="100" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TBODY>
<TR> <TD width="100" style="height: 170px"> <img src="image/111.jpg" /></TD>
</TR> </TBODY></TABLE>
</TD> </TR> <TR> <TD> <form id="login" method="post" runat="server">
<TABLE height="100" cellSpacing="0" cellPadding="0" border="0">
<TBODY>
<TR>
<TD align="right" width="35%" style="height: 30px">公司名称:</TD>
<TD style="height: 30px; width: 188px;">
<select id="Select1" style="width: 160px">
<option selected="selected">优依软件</option>
<option selected="selected">中国科技</option>
<option selected="selected">江苏企业</option>
 </select>
 <asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator" controlToValidate="username" errormessage='公司名称' display="dynamic">*</asp:RequiredFieldValidator>
        </TD> </TR>
<TR>
<TD align="right" width="35%" height="30">
          用 户 名:</TD>
<TD style="width: 188px">
<asp:textbox class="inputNormal" id="username" runat="server" Width="160px"></asp:textbox>
<asp:RequiredFieldValidator runat="server" id="LoginIDRequiredFieldValidator" controlToValidate="username" errormessage='用户名' display="dynamic">*</asp:RequiredFieldValidator>
</TD>
</TR>
<TR>
<TD align="right" width="35%" height="30">密&nbsp;&nbsp;&nbsp; 码:</TD>
<TD style="width: 188px">
<asp:textbox id="password" class="inputNormal" runat="server" TextMode="Password" Width="160px">*</asp:textbox>
<asp:RequiredFieldValidator runat="server" id="LoginPasswordRequiredFieldValidator" controlToValidate="password" errormessage='密码 ' display="dynamic">*</asp:RequiredFieldValidator>
</TD>
</TR>
<TR>
<TD align="right" colSpan="2" height="18">
<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
<TBODY>
<TR>
<TD width="100%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:button id="btnlogin" runat="server" Width="66px" Height="29px" Text="登录" OnClick="btnlogin_Click"></asp:button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
                                                                                    <asp:button id="Button1" runat="server" Width="66px" Height="29px" Text="取消"></asp:button></TD>
</TR>
<TR>
<TD colspan="4" style="width: 242px">
<span id="errorSpan" class="error">
<br>
<asp:ValidationSummary id="LogonValidationSummary" runat="server" HeaderText="请正确填入以下的内容:" />
</span>
</TD>
</TR>
</TBODY></TABLE>
</TD>
</TR>
</TBODY></TABLE>
</form>
</TD>
</TR>
</TBODY></TABLE>
</TD>
</TR>
</TBODY></TABLE>
</CENTER>
</DIV>
</BODY>
</HTML>

解决方案 »

  1.   

    <script   runat="server"> 
            protected   void   btnlogin_Click(object   sender,   EventArgs   e) 
            {       
            } 
    </script> 
    ???
    没有用单独的cs文件?
    不就是连接数据库,匹配用户名个密码吗
      

  2.   

    写个后台 程序嘛   我复制段我以前的private void Button1_Click(object sender, System.EventArgs e)
    {
    if(this.RadioButtonList1.SelectedValue=="学生")
    {
    this.sqlCommand1.CommandText="select * from student where 学号='"+this.TextBox1.Text.Trim()+"' and 密码='"+this.TextBox2.Text.Trim()+"'";
    this.sqlConnection1.Open();
    SqlDataReader dr=this.sqlCommand1.ExecuteReader();
    if(dr.HasRows)
    {
    Session["xh"]=this.TextBox1.Text.Trim();
    this.Response.Redirect("stushow.aspx");
    }
    else
    {
    this.Response.Write("<script language='javascript'>alert('登陆失败,请检查用户名或密码!');</script>");
    this.Response.Write("<script language='javascript'>self.parent.location.href='index.aspx';</script>");
    this.TextBox1.Text="";
    }
    this.sqlConnection1.Close();
    }
    else
    {
    this.sqlCommand1.CommandText="select * from manager where 用户名='"+this.TextBox1.Text.Trim()+"' and 密码='"+this.TextBox2.Text.Trim()+"'";
    this.sqlConnection1.Open();
    SqlDataReader dr=this.sqlCommand1.ExecuteReader();
    if(dr.HasRows)
    {
    Session["gly"]=this.TextBox1.Text.Trim();
    this.Response.Redirect("manage.aspx");
    }
    else
    {
    this.Response.Write("<script language='javascript'>alert('登陆失败,请检查用户名或密码!');</script>");
    this.Response.Write("<script language='javascript'>self.parent.location.href='index.aspx';</script>");
    this.TextBox1.Text="";
    }
    this.sqlConnection1.Close();
    }
    }