要求:用户名和密码从数据库中读取,如正确,提示“登录成功”;如错误,给出错误提示。
解决方案 »
- asp.net(C#)上传到服务器怎么配置
- 新手问题,快把我弄疯了,
- asp.net usbkey的问题
- session的问题
- 请问Asp.net中的登录控用到的是数据库中的哪个表?
- 为过程或函数 根据电邮返回客户编号 指定的参数太多。
- 高分求 怎么从服务器上复制文件夹下的所有文件到本地?
- WebServices中的中文乱码问题(请教思归、孟子E章)?
- 获取gridview中DropDownList和RadioButtonList的值
- aspnet.mvc <input type="file" name="files" multiple="multiple" /> 多图片上传
- 为什么这个方法没法关闭弹出的页面呢?
- 脚本语言
当然你直接用服务器控件的按钮,在Click事件里写代码也可以,但是这样做会刷新界面。
<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结束-->
{
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");
}
}
这老师,教神马呢?有些东西必须让老师负责的!哪怕是XXX鸟老师也不能这个样子啊。
if(textbox1.Text=="用户名"&&textbox2.Text=="密码")
{
Response.Write("alert('成功')");
}
else
{
Response.Write("alert('失败')");
}