从ajax调用vb pagemethod

时间:2011-02-18 04:45:12

标签: asp.net ajax vb.net pagemethods ajax.net

您好 我有一个带有2个文本框的简单aspx文件和一个附加到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

这不起作用..我怎样才能使它工作?

1 个答案:

答案 0 :(得分:1)

应该共享您的功能:

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

检查脚本管理器标记中的EnablePageMethods="true"