Ajax|asp.net| Program
ASP.net Ajax is a lot different from Atlas. A few points can be seen from this simple example.
<1> Create a new asp.net ajax-enabled web site
<2> page layout. The Server controls tag prefix (tag Prefix) becomes ASP from Atlas;
<%@ 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" >
<title>Hello</title>
<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= "a" id= "name"/>
<input type= "button" id= "Button1" value= "Greetings"/>
<div id= "Result" ></div>
</div>
</form>
</body>
<script type= "Text/javascript" >
function SayHello ()
{
var fs = HelloWorldService;
Fs.set_defaultsucceededcallback (OnShow);
Fs. HelloWorld (document.getElementById ("name"). Value);
}
function OnShow (Result)
{
var s = document.getElementById ("result");
S.innertext = result;
}
</script>
<4>helloworldservice Service Code. In order for the service to be invoked by ASP.net AJAX clients, the service must be specified with the [ScriptService] attribute (in order to use this property, reference to the Microsoft.Web.Script.Services namespace).
1using System;
2using System.Web.Services;
3using System.Web.Services.Protocols;
4using Microsoft.Web.Script.Services;
5
6[webservice (Namespace = "http://tempuri.org/")]
7[webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)]
8[scriptservice]
9public class HelloWorldService:System.Web.Services.WebService {
10
One public HelloWorldService () {
12
//uncomment the following line if using designed components
//initializecomponent ();
15}
16
[WebMethod]
public string HelloWorld (string name) {
A String hello = String.IsNullOrEmpty (name)? "Anonymous": Name;
Hello + = "Hi, the current server time is:";
Hello + + DateTime.Now.ToUniversalTime ();
return hello;
23}
24
25}
Http://www.cnblogs.com/sharpaxe/archive/2006/10/24/538395.html