|
|
Registered tutorials: 501 Registered Users: 29843
|
|
Rating: 4.27 out of 11 votes cast
Category: Ajax and .NET
|
Simple Asp.Net + Ajax example
Abstract: A short introduction to Ajax. Shows simple example how to organize the Ajax behaviour in the ASP.NET application
IntroductionI’m going to tell you new piece of Ajax information. Ok what’s Ajax? - Asynchronous JavaScript + XML, new great technology which closely related with conception of web2. If you saw amazing products of Google(gmail, google maps) you could notice that this applications is very similar with usual desktop applications it’s Ajax. The main point of using it is the great usability, speed of interactions and a big traffic’s economy. And your applications don’t need postbacks!!! But it has one disadvantage you need to write a lot of client side code so you should be careful to manage with it. Body
I’m not going to tell something tricky today I’m just want to tell about basics to make your understanding better. It’ll be button which asynchronously calls server, client side processes response and displays result in a Lable. At first I’ll show commented code then will give some explanations. Code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <script type ="text/javascript" language="jscript"> var obj; function getXMLHTTPRequest() { var xRequest=null; if (window.XMLHttpRequest) { xRequest=new XMLHttpRequest(); }else if (typeof ActiveXObject != "undefined"){ xRequest=new ActiveXObject("Microsoft.XMLHTTP"); } return xRequest; } function GetDataUsingAJAX() { obj=getXMLHTTPRequest(); if(obj!=null) { obj.onreadystatechange = ProcessResponse; obj.open("GET", "http://localhost:1392/Ajax1/ProcessedPage.aspx", true); obj.send(null); } return false; } function ProcessResponse() { if(obj.readyState == 4) { if(obj.status == 200) { var retval=obj.responseText; if (document.getElementById("Label1")!=null) document.getElementById("Label1").innerHTML=retval; } else { alert("Error retrieving data!" ); } } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div> </form> </body> </html>
|
Reviews:
Rate and Review This Site
No reviews yet
Statistic Information About this Resource:
| Total Hits: |
2904 |
| Unique Hits: |
2445 |
| |
Daily |
Weekly |
Monthly |
| |
Unique |
Total |
Unique |
Total |
Unique |
Total |
| Average |
0.2 |
0.2 |
56 |
69 |
94.5 |
115 |
| Current |
1 |
1 |
2 |
2 |
2 |
2 |
| Previous |
1 |
1 |
0 |
0 |
542 |
671 |
| Oct 12 |
0 |
0 |
53 |
64 |
22 |
23 |
| Oct 11 |
0 |
0 |
129 |
158 |
110 |
136 |
| Oct 10 |
0 |
0 |
153 |
200 |
11 |
11 |
| Oct 9 |
0 |
0 |
96 |
119 |
0 |
0 |
| Oct 8 |
0 |
0 |
111 |
130 |
15 |
17 |
| Oct 7 |
0 |
0 |
3 |
3 |
236 |
279 |
| Oct 6 |
0 |
0 |
9 |
10 |
7 |
11 |
| Oct 5 |
0 |
0 |
4 |
4 |
0 |
0 |
| Highest |
34 |
43 |
153 |
200 |
542 |
671 |
|
|
|
Script Execution Time: 0.21607 | SQL Queries: 10 | Members: 501
Ajax Tutorial Top List - Powered by Aardvark Topsites PHP 5.1.2
|