I found a strange problem when ASP. NET Ajax calls WebService on the client! The problem is even more strange !!

Source: Internet
Author: User

Yesterday I used the same code as below, and today the same code is not changed at all. But when I look at this program again today, it doesn't even say "the object cannot be found". Everything is normal !!!!

Is this really a matter of character in the legend ?? Depressed !!

I found that when I write a WebService file using the "Code Page placed in a file separately", it will appear ".. Not defined.

The ASPX page code is as follows:

1 <div>
2 <asp: scriptmanager id = "scriptmanager1" runat = "server">
3 <services>
4 <asp: servicereference Path = "Hello. asmx"/>
5 </services>
6 </ASP: scriptmanager>
7 </div>
8 <input id = "button1" type = "button" value = "button" Language = "JavaScript" onclick = "Return button1_onclick () "/> 1 <script language =" JavaScript "type =" text/JavaScript ">
2 <! --
3
4 function button1_onclick (){
5 hello. sayhello ('OK', onsucceed );
7}
8
9 function onsucceed (result)
10 {
11 alert (result );
12}
13
14 // -->

Hello. asmx: 1 without code separation <% @ WebService Language = "C #" class = "hello" %>
2
3 using system;
4 using system. Web;
5 using system. Web. Services;
6 using system. Web. Services. Protocols;
7 using system. Web. Script. Services;
8
9 [WebService (namespace = "http://tempuri.org/")]
10 [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
11 [scriptservice]
12 public class Hello: system. Web. Services. WebService
13 {
14 [webmethod]
15 Public String sayhello (string name)
16 {
17 return string. Format ("WebService Hello {0}", name );
18}
19}

To separate the CS code, put it in a CS file, which is in the app_code folder.

Who can tell you that it is not possible when code separation is used ??

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.