我做个前台登陆界面,可能有错啊,请教大家如何连接数据库对身份验证,正确进入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">密 码:</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%"> <asp:button id="btnlogin" runat="server" Width="66px" Height="29px" Text="登录" OnClick="btnlogin_Click"></asp:button>
<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>
我的代码如下:
<%@ 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">密 码:</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%"> <asp:button id="btnlogin" runat="server" Width="66px" Height="29px" Text="登录" OnClick="btnlogin_Click"></asp:button>
<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>
解决方案 »
- C# 自动更新下载文件列表
- 联通 短信 sp端 代码。。
- winform datagrid 多层绑定ArrayList的问题。在线等。最后10分,大家原谅。
- 记事本如何获得光标位置
- 字符串数组类型的object,如何转换为string[],急!急!急!100分
- 关于系统之间的WebService的调用
- winform 下的datagrid 产生的莫名其妙的错误! 谢谢
- 怎么查看某个端口是否在使用-(急呼高手,急啊)
- 三层的困惑!
- WPF,Binding绑定
- 超难的问题,关于三层 面向对象 数据更新技术 太综合了 请专家高手们进来详细看看
- 使用.NET 快4年了,总感觉还是入门级别,有同感的朋友讨论一下,高手指导一下啊!!
protected void btnlogin_Click(object sender, EventArgs e)
{
}
</script>
???
没有用单独的cs文件?
不就是连接数据库,匹配用户名个密码吗
{
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();
}
}