The so-called asynchronous refresh is not to refresh the entire Web page to update data.
Ajax can be achieved only through JS, and then asynchronous refreshes are implemented
The difference between the form submission data and the AJAX submission data: The form submission is the data from the entire page submitted, and the previous page (Refresh page) is discarded when the data is submitted; Ajax extracts some data from the current page and submits it, and receives the returned data, which is processed and then displayed on the current page (without refreshing the page).
"Example" = = Verify that the user name is repeated = =
Use the idea of Ajax: Write JS and Ajax code in the page to be refreshed, submit the data to another page, write the query code in Page_Load and return the results to the refreshed page.
Interface
I. Using LINQ to connect to a database
Second, import the jquery file into the project. Code written in
<script src= "Js/jquery-1.2.3.pack.js" type= "Text/javascript" ></script>
Third, write the following code on the refreshed page. Code written in
<script src= "Js/jquery-1.2.3.pack.js" type= "Text/javascript" ></script> <%--call Jquery--%> < Script> $ (document). Ready (//Trigger function Getval () {$ ("#TextBox1") when the page has finished loading. blur (Fu Nction () {///when the mouse clicks or leaves, the var txt = $ (this) is triggered. Val ();//Gets the value of the text box//use AJAX to send out the value of the text box $.ajax ({url: "de.aspx", type: "POST", Data: {id:txt},//receive the information returned by the database datatype: "XML", Data in the Success:function (data) {//data is the data in the De page that is the Count of var co = $. Text (); if (parseint (CO) = = 0) {var lbl = document.getElementById ("Label1") ;//Use JS output lbl.innerhtml = "√"; } else {var lbl = Document.getelemEntbyid ("Label1"); lbl.innerhtml = "This user name is registered"; } } }); }); }); </script>
Iv. write the following code in the Page_Load on the page where the value is passed
protected void Page_Load (object sender, EventArgs e) { //query data sent over dataclassesdatacontext dc = new Dataclassesdatacontext (); String uid = request["id"]. ToString (); int count = DC. Stopro.where (r = r.stoid = = Int. Parse (UID)). Count (); Returns Response.Write as XML ("<?xml varsion= ' 1.0 '?>"); Response.Write ("<count>" + Count + "</count>"); Response.End ();//Turn off Response }
Complete!
How to write Ajax for asynchronous refreshes