ASP.NET登錄注冊(cè)頁(yè)面實(shí)現(xiàn)
如何利用Visual studio 2010創(chuàng)建一個(gè)ASP網(wǎng)站?
【文件】-->【新建】-->【網(wǎng)站】-->【ASP.Net網(wǎng)站】--【完成】
默認(rèn)頁(yè)面Default.aspx
創(chuàng)建以上界面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserLogin.aspx.cs" Inherits="UserLogin" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <div align="center"> <h1>用戶登錄頁(yè)面</h1> <form id="form1" runat="server"> <p> <asp:Label ID="lbusername" runat="server">用戶名:</asp:Label> <asp:TextBox ID="tbusername" runat="server"></asp:TextBox> </p> <p> <asp:Label ID="lbpsw" runat="server">密 碼:</asp:Label> <asp:TextBox ID="tbpsw" runat="server" TextMode="Password"></asp:TextBox> </p> <p><asp:Button ID="btnLogin" runat="server" Text="登錄" onclick="btnLogin_Click" /> <asp:Button ID="btnCancel" runat="server" Text="取消" onclick="btnCancel_Click" /> </p> </form> </div> </body> </html>
登錄驗(yàn)證功能
/// <summary> /// 用戶登錄 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnLogin_Click(object sender, EventArgs e) { if (tbusername.Text == "") { Response.Write(@"<script>alert('用戶名不能為空!');</script>"); } if (tbpsw.Text == "") { Response.Write(@"<script>alert('密碼不能為空!');</script>"); } string username = tbusername.Text; string password = tbpsw.Text; string sql = "select * from T_user where username=@username and password=@password"; SqlParameter[] parameters = { new SqlParameter("@username",username), new SqlParameter("@password", password) }; using (SqlConnection conn = new SqlConnection(connstr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(ds); DataTable table = ds.Tables[0]; if(table != null) Response.Write(@"<script>alert('登錄成功!');</script>"); else Response.Write(@"<script>alert('登錄失?。?);</script>"); } } }
注冊(cè)功能
/// <summary> /// 用戶注冊(cè) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void brnRegister_Click(object sender, EventArgs e) { string username = tbusername.Text; string password = tbpsw.Text; string sql = "Insert into T_user(username, password) values(@username,@password)"; SqlParameter[] parameters = { new SqlParameter("@username", username), new SqlParameter("@password", password) }; using (SqlConnection conn = new SqlConnection(connstr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); cmd.ExecuteNonQuery(); } } Response.Write(@"<script>alert('注冊(cè)成功!');</script>"); }
知識(shí)點(diǎn)歸納:
1.如何創(chuàng)建一個(gè)ASP.Net網(wǎng)站
2. 使用服務(wù)器控件實(shí)現(xiàn)界面設(shè)計(jì)
3. 對(duì)數(shù)據(jù)庫(kù)的簡(jiǎn)單操作
一個(gè)簡(jiǎn)單的用戶注冊(cè)、登錄就完成了,通過這個(gè)案例希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
Asp.Net Core添加請(qǐng)求頭自定義認(rèn)證的示例
這篇文章主要介紹了Asp.Net Core添加請(qǐng)求頭自定義認(rèn)證的示例,幫助大家更好的理解和學(xué)習(xí)使用.net技術(shù),感興趣的朋友可以了解下2021-04-04asp.net通過js實(shí)現(xiàn)Cookie創(chuàng)建以及清除Cookie數(shù)組的代碼
asp.net Cookie創(chuàng)建以及清除Cookie數(shù)組2010-03-03asp.net下linkbutton的前后臺(tái)使用方法
asp.net LinkButton傳遞參數(shù)2008-08-08在.ashx文件中獲取cookies值實(shí)現(xiàn)代碼
.ashx文件中獲取cookies值對(duì)于一些高手們就不多說了,至于一些小白們還是有必要多多學(xué)習(xí)啊,好了話不多說,看代碼,感興趣的你可不要錯(cuò)過了哈2013-02-02設(shè)置默認(rèn)Ajax操作cache and error
設(shè)置默認(rèn)Ajax操作cache and error,需要的朋友可以參考一下2013-02-02在阿里云函數(shù)計(jì)算上部署.NET Core 3.1的方法
這篇文章主要介紹了在阿里云函數(shù)計(jì)算上部署.NET Core 3.1的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07asp.net下GDI+的一些常用應(yīng)用(水印,文字,圓角處理)技巧
asp.net下GDI+的一些常用應(yīng)用(水印,文字,圓角處理)技巧...2007-03-03Asp.net MVC利用knockoutjs實(shí)現(xiàn)登陸并記錄用戶的內(nèi)外網(wǎng)IP及所在城市(推薦)
這篇文章主要介紹了 Asp.net MVC利用knockoutjs實(shí)現(xiàn)登陸并記錄用戶的內(nèi)外網(wǎng)IP及所在城市(推薦),需要的朋友可以參考下2017-02-02ASP.NET MVC使用EPPlus,導(dǎo)出數(shù)據(jù)到Excel中
這篇文章介紹的是怎樣導(dǎo)出數(shù)據(jù)到Excel文件中,大多數(shù)的后端程序都有報(bào)表功能:把顯示在Grid中的數(shù)據(jù)導(dǎo)出到Excel文件中,這篇文章中使用的是EPPlus組件。需要的朋友可以參考借鑒2016-12-12Razor TagHelper實(shí)現(xiàn)Markdown轉(zhuǎn)HTML的方法
下面小編就為大家分享一篇Razor TagHelper實(shí)現(xiàn)Markdown轉(zhuǎn)HTML的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-12-12