Asp. NET Classroom-Experiment 1 (Login Registration page implementation)

Source: Internet
Author: User
Tags visual studio 2010
ASP. NET Classroom-Experiment 1 (Login Registration page implementation)




How to create an ASP Web site using 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 ">  

Implementing logon Verification Features
 <summary>///User Login///</summary>///<param name= "sender" ></param>///<p Aram Name= "E" ></param> protected void Btnlogin_click (object sender, EventArgs e) {if (tbusername . Text = = "") {Response.Write (@) <script>alert (' User name 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> "); }
        }

        
    }



Experiment 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 successfully.") ');</script> ");
    }

Knowledge Points: 1. How to create a asp.net website 2. Implementing interface design using server Controls 3. Simple operations on a database



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.