昨天的我用的是下面的同样的代码,今天的也是同样的代码,一点都没有改。可是今天我再来看本程序的时候,它竟然不说“找不到对象”了,一切正常!!!!
这莫非真的是传说中的人品问题么??郁闷!!
我发现在写WebService文件时如果采用"代码页单独放置在一个文件中"时,就会出现"。。未定义",可是不采用"代码页放置在一个单独文件中"时,就不会出任何问题。
aspx页面代码如下:
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()" />
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
4function Button1_onclick() {
5 Hello.SayHello('ok',OnSucceed);
7}
8
9function OnSucceed(result)
10{
11 alert(result);
12}
13
14// -->
2<!--
3
4function Button1_onclick() {
5 Hello.SayHello('ok',OnSucceed);
7}
8
9function OnSucceed(result)
10{
11 alert(result);
12}
13
14// -->
不采用代码分离的方式的Hello.asmx:
1<%@ WebService Language="C#" Class="Hello" %>
2
3using System;
4using System.Web;
5using System.Web.Services;
6using System.Web.Services.Protocols;
7using System.Web.Script.Services;
8
9[WebService(Namespace = "http://tempuri.org/")]
10[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
11[ScriptService]
12public 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}
2
3using System;
4using System.Web;
5using System.Web.Services;
6using System.Web.Services.Protocols;
7using System.Web.Script.Services;
8
9[WebService(Namespace = "http://tempuri.org/")]
10[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
11[ScriptService]
12public 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}
分离的话就是将CS代码单独地放在一个cs文件中,该文件在App_Code文件夹中。
谁能告诉在使用代码分离的时候它就不可以呢??
点个广告: