ASP.NET和VB.NET中的AutoComplete TextBox无法正常工作。 [英] AutoComplete TextBox in ASP.NET and VB.NET is not working.

查看:69
本文介绍了ASP.NET和VB.NET中的AutoComplete TextBox无法正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio 2008和AjaxToolKit 3.5来完成自动完成TextBox但是尽管我已经完成了所有工作,即使我在程序运行时没有收到任何错误消息,我的自动完成TextBox无法正常工作。下面是ASP.NET和VB.NET中的各种代码。如果有人可以帮助我,我会很高兴。







<%@ Page Language =VBAutoEventWireup =falseCodeFile =Subjects.aspx.vbInherits =Subjects%>



<%@ Register Assembly = AjaxControlToolkitNamespace =AjaxControlToolkitTagPrefix =cc1%>



<%@ Register assembly =System.Web.Extensions,Version = 3.5。 0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35namespace =System.Web.UItagprefix =asp%>





I''m trying to use Visual Studio 2008 and AjaxToolKit 3.5 to accomplish auto-complete TextBox but inpitee of all that I have done, even though I''m not recieving any error message when the program is run, my AutoComplete TextBox is not working. Below are the various codes in ASP.NET and VB.NET. I''d be glad if someone could help me out.



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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1"%>

<%@ Register assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" 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">
<head  runat="server">
    <title>Subject Master</title>
    <style type="text/css">
        .style2
        {
        }
        .style4
        {
            width: 297px;
        }
        .style6
        {
            width: 268px;
        }
        .style3
        {
            height: 23px;
            width: 146px;
        }
        .style5
        {
            height: 23px;
            width: 297px;
        }
        .style1
        {
            height: 23px;
            width: 268px;
        }
        .style7
        {
        }
    </style>
</head>
  
<body>
    <form id="frmSubjects"  runat="server">
    <asp:Panel ID="Panel1" runat="server" BackColor="#FFFF99" BorderColor="#00CC00" 

        BorderStyle="Double" Height="721px">
        <div>
       
        </div>
        <p>
            <asp:TextBox ID="txtIdNumber" runat="server" Visible="False" 

            Width="26px"></asp:TextBox>
        </p>
        <table style="width: 66%; height: 552px;" align="center">
            <tr>
                <td class="style2" colspan="2">
                    Subject Code</td>
                <td class="style4" colspan="2">
                    <asp:TextBox ID="txtSubjectCode" runat="server"></asp:TextBox>
                </td>
                <td class="style6" colspan="2">
                    <asp:TextBox ID="txtSearch" runat="server" Width="169px"></asp:TextBox>
                                                       
                </td>
            </tr>
            <tr>
                <td class="style3" colspan="2">
                    Subject Name</td>
                <td class="style5" colspan="2">
                    <asp:TextBox ID="txtSubjectName" runat="server" Width="270px"></asp:TextBox>
                </td>
                <td class="style1" colspan="2">
                     </td>
            </tr>
            <tr>
                <td class="style2" colspan="2">
                    Subject Type</td>
                <td class="style4" colspan="2">
                    <asp:RadioButton ID="rbnCore" runat="server" Text="Core" />
                    <asp:RadioButton ID="rbnElective" runat="server" Text="Elective" />
                </td>
                <td class="style6" colspan="2">
                     </td>
            </tr>
            <tr>
                <td class="style2" colspan="2">
                    Enter User Name</td>
                <td class="style4" colspan="2">
                    <asp:TextBox ID="txtUserId" runat="server"></asp:TextBox>
                </td>
                <td class="style6" colspan="2">
                     </td>
            </tr>
            <tr>
                <td class="style2" colspan="2">
                    Enter Password</td>
                <td class="style4" colspan="2">
                    <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
                </td>
                <td class="style6" colspan="2">
                     </td>
            </tr>
            <tr>
                <td class="style7">
                    <asp:Button ID="btnSave" runat="server" style="text-align: center" Text="Save" 

                    Width="93px" />
                </td>
                <td class="style2" colspan="2">
                    <asp:Button ID="btnClear" runat="server" Text="Refresh" Width="92px" />
                </td>
                <td class="style2" colspan="2">
                    <asp:Button ID="btnUpdate" runat="server" Text="Update" Width="96px" />
                </td>
                <td class="style2">
                    <asp:Button ID="btnDelete" runat="server" Text="Delete" Width="97px" />
                </td>
            </tr>
            <tr>
                <td class="style7">
                     </td>
                <td class="style2" colspan="2">
                     </td>
                <td class="style2" colspan="2">
                     </td>
                <td class="style2">
                     </td>
            </tr>
            <tr>
                <td class="style7" colspan="6">
                    <asp:Label ID="lblMessage" runat="server" 

                    style="text-align: center" Text="Label"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style7" colspan="6">
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
                      </asp:ScriptManager>
                        <cc1:AutoCompleteExtender ServiceMethod="SearchSubjects"

                        ID="AutoCompleteExtender1"

                        MinimumPrefixLength="1"

                        CompletionInterval="100" EnableCaching="False" CompletionSetCount="10" 

                        TargetControlID="txtSearch"

                         runat="server">
                        </cc1:AutoCompleteExtender>
                </td>
            </tr>
            <tr>
                <td class="style7" colspan="6">
                   
                    <asp:Panel ID="Panel2" runat="server" Height="352px" Width="615px" 

                        ScrollBars="Both">
                        
                        <asp:GridView ID="GridView1" runat="server" CellPadding="2" ForeColor="#333333" 

                            GridLines="None" style="text-align: left; top: 1px; left: 180px;" Width="600px">
                            <RowStyle BackColor="#E3EAEB" />
                            <EmptyDataRowStyle BorderStyle="Solid" />
                            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                            <EditRowStyle BackColor="#7C6F57" />
                            <AlternatingRowStyle BackColor="White" />
                        </asp:GridView>
                        </asp:Panel>
                </td>
            </tr>
        </table>
    </asp:Panel>
        <div>
     </div>
        </form>
</body>
</html>









In the web.config, I added the following:











In the web.config, I added the following:



<controls>
         <add tagPrefix="cc1" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
				<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
				<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
			</controls>
















<System.Web.Script.Services.ScriptMethod(), System.Web.Services.WebMethod()> _
  Public Shared Function SearchSubjects(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
        Dim conn As SqlConnection = New SqlConnection
        conn.ConnectionString = ConfigurationManager _
             .ConnectionStrings("Data Source=EBENEZERAKAGLO\SQLEXPRESS;Initial Catalog=Naass;Integrated Security=True").ConnectionString
        Dim cmd As SqlCommand = New SqlCommand
        cmd.CommandText = "select SubjectName from ProgramDetails.Subjects where" & _
            " SubjectName like @SearchText + '%'"
        cmd.Parameters.AddWithValue("@SearchText", prefixText)
        cmd.Connection = conn
        conn.Open()
        Dim Subjects As List(Of String) = New List(Of String)
        Dim sdr As SqlDataReader = cmd.ExecuteReader
        While sdr.Read
            Subjects.Add(sdr("SubjectName").ToString)
        End While
        conn.Close()
        Return Subjects
    End Function

推荐答案

According the the ajax library example for autocomplete (found here), your AutoComplete Page method should look something like this:



According the the ajax library example for autocomplete (found here), your AutoComplete Page method should look something like this:

<System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()>
Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()

   Return Nothing
End Function





Your signature looks wrong to me. Your missing the \"ByVal contextKey As String\" parameter, and your returning a generic list instead of an array of string. The return value may not matter... but it might. The signature difference is probably a problem.



I also noticed that your ToolKitScriptManager and your asp:TextBox do not occur in in the same order on your page as they do in the example. This may also be an issue - if I were having a problem getting this to work, I would stay as close to the published example as possible. In the example, they occur in the page like this:





Your signature looks wrong to me. Your missing the "ByVal contextKey As String" parameter, and your returning a generic list instead of an array of string. The return value may not matter... but it might. The signature difference is probably a problem.

I also noticed that your ToolKitScriptManager and your asp:TextBox do not occur in in the same order on your page as they do in the example. This may also be an issue - if I were having a problem getting this to work, I would stay as close to the published example as possible. In the example, they occur in the page like this:

   <asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" xmlns:asp="#unknown">
</asp:toolkitscriptmanager>

<asp:textbox id="txtMovie" runat="server" xmlns:asp="#unknown"></asp:textbox>





Hope this helps,

- Pete



Hope this helps,
- Pete


这篇关于ASP.NET和VB.NET中的AutoComplete TextBox无法正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆