Ajax getting started example (Ajax. NET component usage first)

Source: Internet
Author: User

I am also a newbie. After a long time, I finally wrote my first Ajax instance and shared it. I hope other friends can quickly write their first Ajax instance.Program!

Ajax, short for Asynchronous JavaScript and XML, is Asynchronous JavaScript and XML. Ajax is not a new technology, but a comprehensive application of JavaScript, XML, XMLHttpRequest, and other technologies. The above is the official definition,In my opinion, Ajax is usedCode/Function, which is executed in Javascript mode to achieve the technology of not refreshing the interface. (Purely personal opinion. Welcome to shoot bricks)
Let's get down to the truth. Next we will introduce my first Ajax program:
Program Description: If the interface is not refreshed, click the button to display the server time.
1. Preparation: Download A. Net Ajax Development Kit to get twice the result with half the effort. For more information, see the http://ajax.schwarz-interactive.de. It is a DLL. the version I used is 5.7.25.1, the development environment is vs2005, and the operating system is Vista (UAC disabled ).
2. Create an Asp.net project and add configuration information to Web. config.

1 < System. Web >
2 < Httphandlers >
3 < Add verb = " Post, get " Path = " Ajax/*. ashx " Type = " Ajax. pagehandlerfactory, Ajax "   />
4 </ Httphandlers >
5 </ System. Web >

3. In this Asp.net project, add a pair to create an Asp.net project. (Or copy the file directly to the bin directory)
4. Create a page named mypage. aspx.
Its aspx code: 1 <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Mypage. aspx. CS " Inherits = " Mypage "   %>
2
3 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
4 < Html Xmlns = "Http://www.w3.org/1999/xhtml" >
5 < Head Runat = "Server" >
6 < Title > Untitled page </ Title >
7 </ Head >
8 < Body >
9 < Form ID = "Form1" Runat = "Server" >
10 < Div >
11 < Input Type = "Button" Value = "Click here to get datetime" Onclick = "Javascript: doit ()"   />
12 < BR />
13 < BR />
14 < Textarea ID = "Textarea1" Name = "Mydisplay" Rows = "2" Style = "Width: 506px" Cols = "2" > </ Textarea >
15 </ Div >
16 </ Form >
17
18 < Script Language = "JavaScript" >
19 Function Doit ()
20 {
21Document. Forms [0]. Mydisplay. Value=Mypage. getstring (). value;
22}
23 </ Script >
24
25 </ Body >
26 </ Html >
27

Its CS code 1 Using System;
2 Using System. Data;
3 Using System. configuration;
4 Using System. collections;
5 Using System. Web;
6 Using System. Web. Security;
7 Using System. Web. UI;
8 Using System. Web. UI. webcontrols;
9 Using System. Web. UI. webcontrols. webparts;
10 Using System. Web. UI. htmlcontrols;
11
12 Public Partial Class Mypage: system. Web. UI. Page
13 {
14 Protected   Void Page_load ( Object Sender, eventargs E)
15 {
16Ajax. Utility. registertypeforajax (Typeof(Mypage ));
17}
18
19 [Ajax. ajaxmethod]
20 Public   String Getstring ()
21 {
22Datetime d=Datetime. now;
23Return "The time is" +D. tostring ();
24}
25 }
26

5. Run and click the button to display the server time without refreshing the interface.

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.