Ajax+asp.net to achieve User login

Source: Internet
Author: User

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.

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.