asp.net ajax 1.0,hello World Program

Source: Internet
Author: User
Tags net string
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



Related Article

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.