This article mainly introduces the implementation of Ajax+asp.net user landing, mainly to practice the use of Ajax methods, the need for small partners under the reference.
-->
Take user Login As an example to practice the use of Ajax
Login.html
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72-73 |
<! DOCTYPE html> |
DAL.cs
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Using System; Using System.Collections.Generic; Using System.Data; Using System.Data.SqlClient; Using System.Linq; Using System.Web; Namespace Ajaxtest {public class DAL {private String connstr = ' Server=acer-pc;database=mydatabase;user id=sa;password=1 23456 "; Public DataTable Selectdb (String sql) {DataTable dt = new DataTable (); try {SqlConnection conn = new SqlConnection (Conns TR); SqlDataAdapter SDA = new SqlDataAdapter (SQL, conn); Sda. Fill (DT); catch (Exception e) {} return dt; } } } |
BLL.cs
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Using System; Using System.Collections.Generic; Using System.Data; Using System.Linq; Using System.Web; Namespace Ajaxtest {public class BLL {public bool Login (string username,string password) {try {String sql = ' Select PA ssWOrd from Users where username= ' "+ username +" "; Dal sqlselect = new Dal (); DataTable dt = SQLSELECT.SELECTDB (SQL); if (dt. rows[0]["Password"]. ToString ()!= password) return false; The catch (Exception) {} return true; } } } |
Server.aspx.cs
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28-29 |
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; namespace Ajaxtest {public partial class Server:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {string username = request["username"]. ToString (); string password = request["Password"]. ToString (); BLL B = new BLL (); if (B.login (username, password)) {Response.Write ("Login succeeded"); Response.End (); else {Response.Write ("Login Failed"); Response.End (); } } } } |
Server.aspx
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16-17 |
<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Server.aspx.cs" inherits= "Ajaxtest.server"%> <! DOCTYPE html> |
The above mentioned is the entire content of this article, I hope you can enjoy.