Asp. NET Login Registration page Implementation _ Practical skills

Source: Internet
Author: User
Tags visual studio 2010

How do I create an ASP Web site with Visual Studio 2010?
"File"--> new "-->" Web Site "-->" ASP. NET Web Site "--" complete "

Default page default.aspx
Create the above interface:

<%@ 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 ">  

logon verification feature

<summary>///User Login///</summary>///<param name= "sender" ></param>///<param Nam E= "E" ></param> protected void Btnlogin_click (object sender, EventArgs e) {if (tbusername. Text = = "") {Response.Write (@) <script>alert (' username cannot be empty! 
  ');</script> "); } if (TBPSW. Text = = "") {Response.Write (@) <script>alert (' Password cannot be empty! 
  ');</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) (' Login succeeded! 
    ');</script> "); Else Response.Write (@ "<script>alert Login failed!) 
 
   ');</script> ");  } 
  } 
 
   
 }

Registration function

<summary> 
 ///User Registration 
 ///</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) (' Registered success! ');</script> "); 
 } 

Knowledge Points Summary:
1. How to create a asp.net web site
2. Implement interface design with server control
3. Simple operation of the database

A simple user registration, login is completed, through this case hope to help everyone's study.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.