1

嗨,我有一个简单的 aspx 文件,其中包含 2 个文本框和一个附加到 textbox2 的 ajax 自动完成扩展器

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test4.aspx.vb" Inherits="test4" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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">
<body>
<form id="form1" runat="server">
<div id="content">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:TextBox ID="TextBox1" runat="server">
    </asp:TextBox><br />
    <asp:TextBox ID="TextBox2" runat="server">
    </asp:TextBox>
</div>
<asp:AutoCompleteExtender ID="load_textBox2" TargetControlID="TextBox2" ServiceMethod="GetModelName"
    UseContextKey="True" runat="server">
</asp:AutoCompleteExtender>
</form>
</body>
</html>

我想做的是从aspx.vb中调用pagemethod“GetModelName”来用相关数据填充textbox2 这是aspx.vb代码

Imports System.Web.Services

Partial Class test4
Inherits System.Web.UI.Page
Dim Model_Name_old As String()()
Dim mod_code As String()
Dim mod_name As String()
Dim cod_upper As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    //calling webservice that retunrs a jagged array
    Dim ins As New localhost_insert_model.dbModel

    Model_Name_old = ins.get_Model_Name("A")

    mod_code = Model_Name_old(0)
    mod_name = Model_Name_old(1)
    cod_upper = Model_Name_old(0).GetUpperBound(0)
End Sub
<WebMethod()>
Public Function GetModelName() As String()
    Return mod_name
End Function

End Class

这不工作..我怎样才能让它工作???

4

1 回答 1

2

您的功能应该共享:

<WebMethod()>
Public Shared Function GetModelName() As String()
    Return mod_name
End Function

EnablePageMethods="true"在脚本管理器标签中检查。

于 2011-02-18T04:56:56.900 回答