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.