佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > ASP.NET登錄注冊頁面實現(xiàn)

ASP.NET登錄注冊頁面實現(xiàn)

熱門標(biāo)簽:阿里云 服務(wù)器配置 硅谷的囚徒呼叫中心 地方門戶網(wǎng)站 科大訊飛語音識別系統(tǒng) 集中運營管理辦法 網(wǎng)站排名優(yōu)化 百度競價排名

如何利用Visual  studio 2010創(chuàng)建一個ASP網(wǎng)站?
【文件】-->【新建】-->【網(wǎng)站】-->【ASP.Net網(wǎng)站】--【完成】

默認(rèn)頁面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>用戶登錄頁面/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> 

登錄驗證功能

/// 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>"); 
 
   } 
  } 
 
   
 } 

注冊功能

/// summary> 
 /// 用戶注冊 
 /// /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('注冊成功!');/script>"); 
 } 

知識點歸納:
1.如何創(chuàng)建一個ASP.Net網(wǎng)站
2. 使用服務(wù)器控件實現(xiàn)界面設(shè)計
3. 對數(shù)據(jù)庫的簡單操作

一個簡單的用戶注冊、登錄就完成了,通過這個案例希望對大家的學(xué)習(xí)有所幫助。

您可能感興趣的文章:
  • asp.net BasePage類+Session通用用戶登錄權(quán)限控制
  • ASP.NET中在一般處理程序中使用session的簡單介紹
  • ASP.NET Session使用詳解
  • asp.net(c#)有關(guān) Session 操作的幾個誤區(qū)
  • 一款經(jīng)典的ajax登錄頁面 后臺asp.net
  • ASP.NET MVC5網(wǎng)站開發(fā)用戶登錄、注銷(五)
  • 基于.Net的單點登錄(SSO)實現(xiàn)解決方案
  • .net MVC使用Session驗證用戶登錄(4)

標(biāo)簽:甘孜 隨州 梧州 威海 烏蘭察布 西雙版納 廣西 開封

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET登錄注冊頁面實現(xiàn)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    黔江区| 四平市| 西藏| 芜湖市| 招远市| 沙田区| 类乌齐县| 全南县| 长岛县| 三原县| 聂荣县| 武夷山市| 淅川县| 堆龙德庆县| 米林县| 舒兰市| 佳木斯市| 永定县| 诸城市| 武城县| 稻城县| 南京市| 汤原县| 南涧| 类乌齐县| 措美县| 淳安县| 晋州市| 筠连县| 南漳县| 和顺县| 德江县| 确山县| 略阳县| 咸宁市| 永宁县| 长宁区| 那坡县| 蓬溪县| 曲麻莱县| 玛曲县|