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