asp.net登陆代码下载(ASPNET源码)
admin 发布:2022-12-19 18:16 123
今天给各位分享asp.net登陆代码下载的知识,其中也会对ASPNET源码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
ASP.NET简单的登录 求代码
table
tr
td
asp:Label ID="Label1" runat="server" Text="账号:"/asp:Label/td
td
asp:TextBox ID="txtUserName" runat="server"/asp:TextBox/td
/tr
tr
td
asp:Label ID="Label2" runat="server" Text="密码:"/asp:Label/td
tdasp:TextBox ID="txtPwd" runat="server" TextMode="Password"/asp:TextBox/td
/tr
tr
td style="text-align:center" colspan="2"
asp:Button ID="btnSubmits" runat="server" Text="登录"
onclick="btnSubmit_Click" /
/td
/tr
/table
后台btnSubmit_Click事件
using (SqlConnection sc = new SqlConnection("Data Source=.;Initial Catalog=Test;User ID=sa;Password=yx19891126;"))
{
sc.Open();
string UserName = txtUserName.Text.Trim();
string Password = txtPwd.Text.Trim();
using (SqlCommand cmd = new SqlCommand("select * from Users where UserName='"+UserName+"' Password='"+Password+"'",sc))
{
if (cmd.ExecuteNonQuery() 0)
Response.Write("scriptalert('登录成功');/script");
else
Response.Write("scriptalert('登录失败');/script");
}
}
这是最简单的判断,一些小细节直接忽略了,你可以稍微改改让登录功能更完善
asp.net登录代码
aspx文件
在Web Form里:
加入两个Label控件,Text属性分别为“登录名”和“密码”;
加入两个TextBox控件,ID属性分别为“Userid”和“Pwd”,Text属性均为空;
加入两个RequiredFieldValidato控件,ID属性分别为“rfvUserid”和“rfvPwd”,Text属性分别为“请输入登录名!”和“请输入登录密码!”,ControlToValidate属性分别为"Userid"和"Pwd";
加入一个Button控件,ID属性为“LogButton”,Text属性别为“登录”;
最后加入一个Label控件,ID属性为“Msg”。
Default.aspx源代码如下:
%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="lsj.WebForm1" %
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
HTML
HEAD
meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"
meta name="CODE_LANGUAGE" Content="C#"
meta name="vs_defaultClientScript" content="JavaScript (ECMAScript)"
meta name="vs_targetSchema" content=""
/HEAD
body MS_POSITIONING="GridLayout"
FONT face="宋体"
form runat="server" ID="Form1"
asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 82px; POSITION: absolute; TOP: 39px" runat="server" Width="55px"
Height="26px"登录名/asp:Label
asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 80px; POSITION: absolute; TOP: 84px" runat="server" Width="63px" Height="24px"密 码/asp:Label
asp:TextBox id="txtuser" style="Z-INDEX: 103; LEFT: 161px; POSITION: absolute; TOP: 39px" runat="server" Width="109px" Height="25px"/asp:TextBox
asp:TextBox id="txtpsw" style="Z-INDEX: 104; LEFT: 162px; POSITION: absolute; TOP: 81px" runat="server" Width="109px" Height="22px" TextMode="Password"/asp:TextBox
asp:Button id="LogButton" style="Z-INDEX: 105; LEFT: 79px; POSITION: absolute; TOP: 125px" runat="server" Width="59px" Height="25px" Text="登 录"/asp:Button
asp:Label id="Msg" style="Z-INDEX: 106; LEFT: 161px; POSITION: absolute; TOP: 130px" runat="server" Width="117px" Height="26px"/asp:Label
asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX: 107; LEFT: 290px; POSITION: absolute; TOP: 43px" runat="server" Width="162px" Height="18px" ErrorMessage="RequiredFieldValidator" ControlToValidate="Userid"请输入登录名!/asp:RequiredFieldValidator
asp:RequiredFieldValidator id="RequiredFieldValidator2" style="Z-INDEX: 108; LEFT: 292px; POSITION: absolute; TOP: 83px" runat="server" Width="175px" Height="22px" ErrorMessage="RequiredFieldValidator" ControlToValidate="Pwd"请输入登录密码!/asp:RequiredFieldValidator
/form
/FONT
/body
/HTML
cs文件
using System.Data.Sqlclient;
if(txtuser.Text!="" txtpsw.Text!="")
{ string connsql ="Data Source=(local);Database=StuManger; User id=sa; password=123456";//连接字符串,看着改
SqlConnection conn=new SqlConnection(connsql);
try
{
conn.Open();
}
catch(Exception ex)
{
Response.Write(ex.Message);
return;
}
string mysql="select * from [user] where userName='"+txtuser.Text+"' and psWord='"+txtpsw.Text+""; //表名和字段名也看着改
SqlCommand cmd=new SqlCommand(mysql,conn);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
Response.Write("欢迎进入!");
}
else
{
Response.Write("对不起,您的用户名或密码不正确!");
}
conn.Close();
}
else
{
//Response.Write("用户名或密码不能为空!");
Response.Write("Script Language='JavaScript' window.alert('用户名或密码不能为空!')/Script");
return;
}
asp.net---登陆代码
这应该是最简单的了..不用类..也不用子函数.
protected void Button1_Click(object sender, EventArgs e)
{
string tccuser = this.tccuser.Text.ToString();
string tccpass = this.tccpass.Text.ToString();
string cmdstring = "select * from tcclogin where tccuser = '"+tccuser+"' and tccpass='"+tccpass+"'";
SqlConnection connection = new SqlConnection(connstring);
SqlCommand sqlcmd = new SqlCommand(cmdstring, connection);
SqlDataReader rd;
connection.Open();
rd = sqlcmd.ExecuteReader();
if (rd.Read())
{
Session["username"] = tccuser;
Response.Redirect("index.aspx");
}
else
{
this.Label17.Text = "Wrong username or password!";
}
}
asp.net登陆代码下载的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于ASPNET源码、asp.net登陆代码下载的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:网页qq固定代码(登录页面代码)
- 下一篇:苏宁悬浮代码(苏宁 代码)
相关推荐
- 05-05asp.net输出html代码(html5 asp)[20240505更新]
- 05-05人工智能系统源代码(人工智能代码下载)[20240505更新]
- 05-05易语言源代码下载(易语言下载文件源码)[20240505更新]
- 05-05qq服务器代码下载(服务器怎么下载)[20240505更新]
- 05-05androidoa开源代码(android源码网)[20240505更新]
- 05-05miui开源代码(miui 源码)[20240505更新]
- 05-05androidone代码下载(安卓app代码)[20240505更新]
- 05-04好看登录界面代码(好看的登陆界面)[20240504更新]
- 05-04七夕html代码(七夕网页源码)[20240504更新]
- 05-04网页代码下载html(网页代码下载音乐)[20240504更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接