【求助】做了登录页面,调试没问题,但是在浏览器中登录没有反应,就如没有写后台一般!
登录的时候,页面闪烁一下,就没有反应了,而且验证码、密码、用户名填写错误也没有反应,查了很多资料都没有找到解决的办法,求教大哥哥大姐姐们帮忙呀!谢谢O(∩_∩)O谢谢前台代码:
<table class="style10" bgcolor="#FF99CC">
<tr>
<td>
<span class="style17">登录</span></td>
</tr>
<tr>
<td>
登录名:
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtUserName"
ErrorMessage="用户名必须填写">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
密 码:
<asp:TextBox ID="txtUserpass" runat="server" TextMode="Password"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtUserpass"
ErrorMessage="密码必须填写">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
验证码:
<asp:TextBox ID="txtCode" runat="server" Width="60px"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtCode"
ErrorMessage="验证码必须填写">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<img style="cursor: hand; width: 76px;
height: 21px" id="imgCode" src="Public/CheckCode.aspx"
alt="看不清,请点击我!" onclick="this.src=this.src+'?'" />
</td>
</tr>
<tr>
<td>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" Font-Size="12px" />
</td></tr>
<tr>
<td>
<asp:LinkButton ID="linbtnRegister" runat="server" CausesValidation="False"
PostBackUrl="~/Register.aspx">注册新用户</asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnLog" runat="server" Text="登录" />
<asp:Button ID="Button2" runat="server" Text="重置" />
</td>
</tr>
</table>
后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtCode_TextChanged(object sender, EventArgs e)
{
}
protected void btnLog_Click(object sender, EventArgs e)
{
string code = txtCode.Text;
if (Request.Cookies["CheckCode"].Value == code)
{
SqlConnection con = new SqlConnection("server=.;database=db_XiGeYue;uid=sa;pwd=;");
con.Open();
string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtUserpass.Text, "MD5");
string sqlSel = "select count(*) from tb_userInfo where userName=@username and userPass=@userpass";
SqlCommand com = new SqlCommand(sqlSel, con);
com.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar, 50));
com.Parameters["username"].Value = txtUserName.Text;
com.Parameters.Add(new SqlParameter("userpass", SqlDbType.VarChar, 50));
com.Parameters["userpass"].Value = pass;
if (Convert.ToInt32(com.ExecuteScalar()) > 0)
{
RegisterStartupScript("", "<script>alert('登录成功!')</script>");
txtCode.Text = txtUserName.Text = "";
}
else
{
RegisterStartupScript("", "<script>alert('用户名或密码错误!')</script>");
}
}
else
{
RegisterStartupScript("", "<script>alert('验证码输入错误!')</script>");
}
}
}