I haven't been writing for a long time. I have been busy with my work recently. In addition to the normal work requirements, I have to prepare some documents, ppt and demo, I also spent a lot of time preparing for this Ajax training. The training was finally completed yesterday, and it seemed as easy to handle the requirements. Looking back at the recent work, there were not many problems. Let's take out several client calls to the server today:
1. The client calls the server method: Code in the source file
1 < Script Language = Javascript type = " Text/JavaScript " >
2 Function getcurrenttime ()
3 {
4Pagemethods. getcurrenttime ('Newegg Ajax Training', Checkissuccess );
5}
6 Function checkissuccess (result)
7 {
8Alert (result );
9}
10 </ Script >
11
12 < Input ID = " Button1 " Type = " Button " Value = " Client controls call server Methods " Onclick = " Getcurrenttime () " /> Server Method
1 [Webmethod]
2 Public Static String Getcurrenttime ( String Str)
3 {
4ReturnStr+Datetime. Now. tolongtimestring ();
5}
In this case, the scriptmanager has an attribute: enablepagemethods = "true"
2. The client calls WebService:Source code:
1 < ASP: scriptmanager ID = " Scriptmanager1 " Runat = " Server " >
2 < Services >
3 < ASP: servicereference path = " Ajaxtestwebservice. asmx " Inlinescript = " True " />
4 </ Services >
5 </ ASP: scriptmanager >
6 < BR />
7 This is to use the client method to call the methods in WebService. & Nbsp; < Div >
8 < Input ID = " Button1 " Type = " Button " Value = " Click the method in WebService to generate a random number. " Onclick = " Getrandom () " />
9
10 < Script Language = " Javascript " Type = " Text/JavaScript " >
11 Function getrandom ()
12 {
13Ajax_dear.ajaxtestwebservice.getrandom (getr );
14}
15 Function getr (result)
16 {
17Alert (result );
18}
19 </ Script > WebService Method
1 [WebService (namespace = " Http://tempuri.org/ " )]
2 [Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
3 [Scriptservice]
4 Public Class Ajaxtestwebservice: system. Web. Services. WebService
5 {
6
7 [Webmethod]
8 Public String Helloworld ()
9 {
10Return "Hello World";
11}
12 [Webmethod]
13 Public Int Getrandom ()
14 {
15Return NewRandom (datetime. Now. millisecond). Next ();
16}
17 }
There is nothing to say about it,CodeAll problems,