我正在尝试使用Web服务,当用户单击按钮或更改文本框的文本时,屏幕上应显示一条消息。
但是当我运行代码时,没有任何事情发生;这意味着屏幕上不显示任何警告消息。
有什么想法吗?
Test.aspx文件
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
<Services >
<asp:ServiceReference Path ="~/Services/authenticateUser.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server" onfocus ="Change()" onblur ="Change()"></asp:TextBox>
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<input type="button" value="Get Array" onclick="Change()" />
<span id="spanQuote"></span>
</div>
<script type="text/javascript">
function change() {
authenticateUser.HelloWorld (
function (names) {
var result = '';
for (var i = 0; i < names.length; i++) {
result += names[i] + '\n';
}
alert(result);
}
);
}
</script>
</form>
</body>
</html>
服务/ authenticateUser.asmx
<%@ WebService Language="VB" CodeBehind="~/App_Code/authenticateUser.vb" Class="authenticateUser" %>
**App_Code/authenticateUser.vb**
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.Web.Script.Serialization
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class authenticateUser
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
答案 0 :(得分:3)
在文本框中设置AutoPostBack =“true”。
HTH。