Asp.net Ajax is very different from Atlas. In this simple example, we can see several points.
<1> Create an Asp.net Ajax-enabled web site
<2> page layout. The tag prefix of server controls is changed from Atlas to ASP;
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " Helloworld " %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
< Html >
< Head Runat = "Server" >
< Title > Hello </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< ASP: scriptmanager ID = "Scriptmanager1" Runat = "Server" >
< Services >
< ASP: servicereference Path = "~ /Helloworldservice. asmx" />
</ Services >
</ ASP: scriptmanager >
< Div >
Your name:
< Input Type = "Text" Maxlength = "20" ID = "Name" />
< Input Type = "Button" ID = "Button1" Value = "Greetings" Onclick = "Sayhello ()" />
< Div ID = "Result" > </ Div >
</ Div >
</ Form >
</ Body >
</ Html >
<3> client script. The method for calling the service is somewhat changed. You can specify the default callback method. < Script Type = " Text/JavaScript " >
Function Sayhello ()
{
VaRFS=Helloworldservice;
FS. set_defaultsucceededcallback (onshow );
FS. helloworld (document. getelementbyid ("Name"). Value );
}
Function Onshow (result)
{
VaRS=Document. getelementbyid ("Result");
S. innertext=Result;
}
</ Script >
<4> helloworldservice Code . To enable the Service to be called by the Asp.net Ajax client, you must specify the [scriptservice] attribute for the Service (to use this attribute, you must reference the Microsoft. Web. Script. Services namespace ). 1 Using System;
2 Using System. Web. Services;
3 Using System. Web. Services. Protocols;
4 Using Microsoft. Web. Script. Services;
5
6 [WebService (namespace = " Http://tempuri.org/ " )]
7 [Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
8 [Scriptservice]
9 Public Class Helloworldservice: system. Web. Services. WebService {
10
11 Public Helloworldservice () {
12
13//Uncomment the following line if using designed components
14//Initializecomponent ();
15}
16
17 [Webmethod]
18 Public String Helloworld ( String Name) {
19 String Hello = String. isnullorempty (name) ? " Anonymous " : Name;
20 Hello + = " Hello, the current server time is: " ;
21 Hello + = Datetime. Now. touniversaltime ();
22 Return Hello;
23 }
24
25 }