Take user Login As an example to practice the use of Ajax
Login.html
DAL.cs
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=123456 ";
Public DataTable Selectdb (String sql)
{
datatable dt = new DataTable ();
Try
{
SqlConnection conn = new SqlConnection (CONNSTR);
SqlDataAdapter SDA = new SqlDataAdapter (SQL, conn);
Sda. Fill (DT);
}
catch (Exception e)
{} return
dt;
}
}
}
BLL.cs
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 password from Users where username= '" + username + "'";
Dal sqlselect = new Dal ();
DataTable dt = SQLSELECT.SELECTDB (sql);
if (dt. rows[0]["Password"]. ToString ()!= password) return
false;
}
catch (Exception)
{
} return
true;
}
}}
Server.aspx.cs
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
<%@ 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.