none
为什么 AjaxControlToolkit 3.5 sp1 自带的 AutoComplete 源码 在 IE7 显示为 undefined , 运行时截图如下 RRS feed

答案

  • 你的程序不全,我认为可以从以下方面着手:
    1,确保asmx这个webservice返回i正确格式的值
    2,undefined说明有不存在的变量或者,如果是你自己写的代码,建议将每一个关键步骤进行输出调试信息
    3,网页加载是顺序要求的,尤其是对象引用,则需要在页面完全加载完毕后进行。
    4,如果嵌套进母版页文件,则客户端的id需要采用服务器对象的ClientID来获取

    可以在这几方面进行调试
    孟宪会
    2009年4月16日 1:06
    版主

全部回复

  • 我的ie7没有出现你说的现象。看看你的ie这个地址是否你显示
    http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.asmx

    或者清空你的浏览器缓存看看
    孟宪会
    2009年4月12日 12:26
    版主
  • 清空缓存后,还是老样子,其它的Aiax效果都能显示,唯独AutoComplete 不行!

    输入上述地址后,显示如下

    AutoComplete



    This web service is using http://tempuri.org/ as its default namespace.

    Recommendation: Change the default namespace before the XML Web service is made public.

    Each XML Web service needs a unique namespace in order for client applications to distinguish it from other services on the Web. http://tempuri.org/ is available for XML Web services that are under development, but published XML Web services should use a more permanent namespace.

    Your XML Web service should be identified by a namespace that you control. For example, you can use your company's Internet domain name as part of the namespace. Although many XML Web service namespaces look like URLs, they need not point to actual resources on the Web. (XML Web service namespaces are URIs.)

    For XML Web services creating using ASP.NET, the default namespace can be changed using the WebService attribute's Namespace property. The WebService attribute is an attribute applied to the class that contains the XML Web service methods. Below is a code example that sets the namespace to "http://microsoft.com/webservices/":

    C#

    [WebService(Namespace="http://microsoft.com/webservices/")]
    public class MyWebService {
        // implementation
    }

    Visual Basic

    <WebService(Namespace:="http://microsoft.com/webservices/")> Public Class MyWebService
        ' implementation
    End Class

    C++

    The following operations are supported. For a formal definition, please review the Service Description.

    2009年4月12日 12:58
  • 清空缓存后,还是老样子,其它的Aiax效果都能显示,唯独AutoComplete 不行!

    输入上述地址后,显示如下

    AutoComplete


     

    The following operations are supported. For a formal definition, please review the Service Description.


    This web service is using http://tempuri.org/ as its default namespace.

    Recommendation: Change the default namespace before the XML Web service is made public.

    Each XML Web service needs a unique namespace in order for client applications to distinguish it from other services on the Web. http://tempuri.org/ is available for XML Web services that are under development, but published XML Web services should use a more permanent namespace.

    Your XML Web service should be identified by a namespace that you control. For example, you can use your company's Internet domain name as part of the namespace. Although many XML Web service namespaces look like URLs, they need not point to actual resources on the Web. (XML Web service namespaces are URIs.)

    For XML Web services creating using ASP.NET, the default namespace can be changed using the WebService attribute's Namespace property. The WebService attribute is an attribute applied to the class that contains the XML Web service methods. Below is a code example that sets the namespace to "http://microsoft.com/webservices/":

    C#

    [WebService(Namespace="http://microsoft.com/webservices/")]
    public class MyWebService {
        // implementation
    }

    Visual Basic

    <WebService(Namespace:="http://microsoft.com/webservices/")> Public Class MyWebService
        ' implementation
    End Class

    C++

    2009年4月12日 12:59
  • 有没有知道原因呀,很急!
    2009年4月13日 11:00
  • 将浏览器的禁止脚本调试去掉,看看哪个地方出错的,提示什么代码出错


    孟宪会
    2009年4月13日 14:36
    版主
  • 顶,关注。
    做最好的自己
    2009年4月13日 14:46
  • 去掉 禁止脚本调试 后,重启IE  结果还是老样子
    2009年4月14日 11:04
  • 再看一个例子,三个框中,有一个能正常显示:






    示例文件为  AjaxControlToolkit-Framework3.5SP1\ToolkitTests  中的 AutoComplete.aspx   ,未作任何修改 ,文件源代码:

    <%@ Page
        Language="C#"
        MasterPageFile="~/Default.master"
        CodeFile="AutoComplete.aspx.cs"
        Inherits="Automated_AutoComplete"
        Title="AutoComplete Tests"
        %>
       
        <script runat="server">
            [System.Web.Services.WebMethod]
            [System.Web.Script.Services.ScriptMethod]
            public static string[] GetCompletionListWithContext(string prefixText, int count, string contextKey)
            {
                if (contextKey != null)
                    return "this is a total of fifteen words that will be returned when we use context".Split(' ');
                   
                if (count == 0)
                {
                    count = 10;
                }

                if (prefixText.Equals("xyz"))
                {
                    return new string[0];
                }

                ArrayList items = new ArrayList(count);
                Random random = new Random();
                for (int i = 0; i < count; i++)
                {
                    char c1 = (char)random.Next(65, 90);
                    char c2 = (char)random.Next(97, 122);
                    char c3 = (char)random.Next(97, 122);

                    items.Add(prefixText + c1 + c2 + c3);
                }

                return (string[])items.ToArray(typeof(string));
            }

            [System.Web.Services.WebMethod]
            [System.Web.Script.Services.ScriptMethod]
            public static string[] GetCompletionListWithContextAndValues(string prefixText, int count, string contextKey)
            {
                System.Collections.Generic.List<string> items = new System.Collections.Generic.List<string>(GetCompletionListWithContext(prefixText, count, contextKey));
                for (int i = 0; i < items.Count; i++)
                {
                    items[i] = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(items[i], i.ToString());
                }
                return items.ToArray();
            }
        </script>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
        <div id="listID1"></div>
        <ajaxToolkit:AutoCompleteExtender
            ID="AutoCompleteExtender1"
            runat="server"
            TargetControlID="TextBox1"
            ServiceMethod="GetCompletionList"
            ServicePath="ToolkitTestService.asmx"
            MinimumPrefixLength="3"
            EnableCaching="true"
            CompletionSetCount="5"
            CompletionInterval="1000"
            BehaviorID="autoCompleteBehavior1"
            />
        <br /><br />   
        <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
        <ajaxToolkit:AutoCompleteExtender
            ID="AutoCompleteExtender2"
            runat="server"
            TargetControlID="TextBox2"
            ServiceMethod="GetCompletionListWithContext"
            UseContextKey="true"
            MinimumPrefixLength="2"
            EnableCaching="false"
            CompletionSetCount="10"
            CompletionInterval="2000"
            BehaviorID="autoCompleteBehavior2"
            FirstRowSelected="true"
            DelimiterCharacters=";," />
        <br /><br />   
        <asp:TextBox ID="TextBox3" runat="server" ></asp:TextBox>
        <ajaxToolkit:AutoCompleteExtender
            ID="AutoCompleteExtender3"
            runat="server"
            TargetControlID="TextBox3"
            ServiceMethod="GetCompletionListWithContextAndValues"
            UseContextKey="true"
            MinimumPrefixLength="2"
            EnableCaching="false"
            CompletionSetCount="10"
            CompletionInterval="1000"
            BehaviorID="autoCompleteBehavior3" />
     <br /><br />   
        <asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox>
        <ajaxToolkit:AutoCompleteExtender
            ID="AutoCompleteExtender4"
            runat="server"
            TargetControlID="TextBox4"
            ServiceMethod="GetCompletionList"
            ServicePath="ToolkitTestService.asmx"
            MinimumPrefixLength="3"
            EnableCaching="true"
            CompletionSetCount="5"
            CompletionInterval="1000"
            BehaviorID="autoCompleteBehavior4"
            FirstRowSelected="true"
            DelimiterCharacters=";,"
            ShowOnlyCurrentWordInCompletionListItem="true" /> 


        <script type="text/javascript">
            // (c) Copyright Microsoft Corporation.
            // This source is subject to the Microsoft Permissive License.
            // See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
            // All other rights reserved.

            // Script objects that should be loaded before we run
            var typeDependencies = ['AjaxControlToolkit.AutoCompleteBehavior'];

            // Test Harness
            var testHarness = null;

            // Controls in the page
            var tb1 = null;
            var autoCompleteBehavior1 = null;
           
            var tb2 = null;
            var autoCompleteBehavior2 = null;
           
            var tb3 = null;
            var autoCompleteBehavior3 = null;
           
            var tb4 = null;
            var autoCompleteBehavior4 = null;
           
            // Ensure the textbox is in its empty state
            function checkEmptyState(autoCompleteList, textBox) {
                return function() {
                    testHarness.fireEvent(textBox, 'onfocus');
                    testHarness.assertEqual('', textBox.value, "TextBox's  text should be '' instead of '" + textBox.value + "'");
                    var children = autoCompleteList.childNodes;           
                    testHarness.assertEqual(children.length, 0, "Div should be have no content when textbox is empty");
                };
            }

            // Test the initial state of the control
            function testInitialState(autoCompleteList, textBox) {
                return function() {
                    checkEmptyState(autoCompleteList, textBox);
                };
            }
           
            // reset content in textbox
            function resetTextBox(textBox) {
                return function(){
                    textBox.value = '';
                };
            }
           
            // Test adding text focus from full control
            function setText(text, textBox) {
                return function(){
                    textBox.value = text;
                    testHarness.fireEvent(textBox, 'onfocus');
                    testHarness.fireEvent(textBox, 'onkeydown');
                };
             }
           
            function checkAutoComplete(numMatches, autoCompleteList){
                return function() {
                    var children = autoCompleteList.childNodes;
                    return (children.length == numMatches);
                };
            }
           
            function verifyAutoCompleteBehavior(text, numMatches, autoCompleteList) {      
                return function() {
                    var children = autoCompleteList.childNodes;
                    testHarness.assertEqual(children.length, numMatches, "Div should have: " + numMatches + " when there are " + text.length + " characters in the textbox; Actual matches: " + children.length);
                    if(children.length > 0) {
                        for (var i = 0; i < numMatches; i++) {
                            var child = children[i];
                            var match = child.innerHTML;
                            testHarness.assertEqual(match.indexOf(text), 0, "Every word should start with text: " + text + " Actual: " + match);
                        }
                    }
                };
            }
           
            function verifySelectedIndex(index, autoCompleteBehavior) {
                return function () {
                    testHarness.assertEqual(autoCompleteBehavior._selectIndex, index, "Selected index should be: " + index + "; Actual: " + autoCompleteBehavior._selectIndex);
                };
            }
           
            function verifyLastWordStartsWith(delimiters, lastWordPrefix, autoCompleteList) {
                return function(){
                    var children = autoCompleteList.childNodes;
                    if(children.length > 0) {
                        for (var i = 0; i < children.length; i++) {
                            var child = children[i];
                            var match = child.innerHTML;
                            var tokens = match.split(delimiters);
                            var lastToken = tokens[tokens.length - 1];
                            testHarness.assertEqual(lastToken.indexOf(lastWordPrefix), 0, "The last word should start with text: " + lastWordPrefix + " Actual: " + lastToken);
                        }
                    }
                };
            }
           
            function verifyValues(autoCompleteList) {
                return function() {
                    var children = autoCompleteList.childNodes;
                    for (var i = 0; i < children.length; i++) {
                        testHarness.assertTrue(i == children[i]._value, "The value of child " + i + " should be '" + i + "' instead of '" + children[i]._value + "'");
                    }
                };
            }
          
            // Register the tests
            function registerTests(harness)
            {
                testHarness = harness;
     
                tb1 = testHarness.getElement('ctl00_ContentPlaceHolder1_TextBox1');
                autoCompleteBehavior1 = testHarness.getObject('autoCompleteBehavior1');
                tb2 = testHarness.getElement('ctl00_ContentPlaceHolder1_TextBox2');
                autoCompleteBehavior2 = testHarness.getObject('autoCompleteBehavior2');
                tb3 = testHarness.getElement('ctl00_ContentPlaceHolder1_TextBox3');
                autoCompleteBehavior3 = testHarness.getObject('autoCompleteBehavior3');           
                // Get the third text box from the page
                tb4 = testHarness.getElement('ctl00_ContentPlaceHolder1_TextBox4');
                autoCompleteBehavior4 = testHarness.getObject('autoCompleteBehavior4');
                                      
                var test = testHarness.addTest('Initial1');
                test.addStep(testInitialState(autoCompleteBehavior1._completionListElement, tb1));
                        
                var test = testHarness.addTest('TextBox1_CharsLessThanLimit');
                test.addStep(setText('ab', tb1), checkAutoComplete(0, autoCompleteBehavior1._completionListElement), 50, 2000, verifyAutoCompleteBehavior('ab', 0, autoCompleteBehavior1._completionListElement));
               
                var test = testHarness.addTest('TextBox1_Reset1');
                test.addStep(resetTextBox(tb1));
                test.addStep(testInitialState(autoCompleteBehavior1._completionListElement, tb1));
                           
                var test = testHarness.addTest('TextBox1_CharsEqualToLimit')
                test.addStep(setText('abc', tb1), checkAutoComplete(5, autoCompleteBehavior1._completionListElement) , 50, 2000, verifyAutoCompleteBehavior('abc', 5, autoCompleteBehavior1._completionListElement));
                               
                var test = testHarness.addTest('TextBox1_Reset2');
                test.addStep(resetTextBox(tb1));
                test.addStep(testInitialState(autoCompleteBehavior1._completionListElement, tb1));           
               
                var test = testHarness.addTest('TextBox1_CharsGreaterThanLimit');
                test.addStep(setText('abcd', tb1), checkAutoComplete(5, autoCompleteBehavior1._completionListElement) , 50, 2000, verifyAutoCompleteBehavior('abcd', 5, autoCompleteBehavior1._completionListElement));
               
                var test = testHarness.addTest('TextBox1_Reset3');
                test.addStep(resetTextBox(tb1));
                test.addStep(testInitialState(autoCompleteBehavior1._completionListElement, tb1));
                                      
                var test = testHarness.addTest('Initial2');
                test.addStep(testInitialState(autoCompleteBehavior2._completionListElement, tb2));
                        
                var test = testHarness.addTest('TextBox2_CharsLessThanLimit');
                test.addStep(setText('a', tb2), checkAutoComplete(0, autoCompleteBehavior2._completionListElement), 50, 3000, verifyAutoCompleteBehavior('a', 0, autoCompleteBehavior2._completionListElement));
               
                var test = testHarness.addTest('TextBox2_Reset1');
                test.addStep(resetTextBox(tb2));
                test.addStep(testInitialState(autoCompleteBehavior2._completionListElement, tb2));
                           
                var test = testHarness.addTest('TextBox2_CharsEqualToLimit')
                test.addStep(setText('ab', tb2), checkAutoComplete(10, autoCompleteBehavior2._completionListElement) , 50, 3000, verifyAutoCompleteBehavior('ab', 10, autoCompleteBehavior2._completionListElement));
                               
                var test = testHarness.addTest('TextBox2_Reset2');
                test.addStep(resetTextBox(tb2));
                test.addStep(testInitialState(autoCompleteBehavior2._completionListElement, tb2));           
               
                var test = testHarness.addTest('TextBox2_CharsGreaterThanLimit');
                test.addStep(setText('abcd', tb2), checkAutoComplete(10, autoCompleteBehavior2._completionListElement) , 50, 3000, verifyAutoCompleteBehavior('abcd', 10, autoCompleteBehavior2._completionListElement));
               
                var test = testHarness.addTest('TextBox2_Reset3');
                test.addStep(resetTextBox(tb2));
                test.addStep(testInitialState(autoCompleteBehavior2._completionListElement, tb2));
               
               
                var test = testHarness.addTest('Service with ContextKey');
                test.addStep(function() { autoCompleteBehavior2.set_contextKey('user specific context...'); });
                test.addStep(setText('abcd', tb2), checkAutoComplete(15, autoCompleteBehavior2._completionListElement) , 50, 3000, verifyAutoCompleteBehavior('', 15, autoCompleteBehavior2._completionListElement));

                var test = testHarness.addTest('First option selected turned off');
                test.addStep(setText('abcd', tb1),
                    checkAutoComplete(5, autoCompleteBehavior1._completionListElement) ,
                    50, 2000,
                    verifySelectedIndex(-1, autoCompleteBehavior1));
               
                var test = testHarness.addTest('First option selected turned on');
                test.addStep(setText('abc', tb2),
                    checkAutoComplete(10, autoCompleteBehavior2._completionListElement) ,
                    50, 3000,
                    verifySelectedIndex(0, autoCompleteBehavior2));
                   
                var test = testHarness.addTest('Multiword autocomplete');
                test.addStep(setText('abc;bcd', tb2),
                    checkAutoComplete(10, autoCompleteBehavior2._completionListElement) ,
                    50, 3000,
                    verifyLastWordStartsWith(";", "bcd", autoCompleteBehavior2._completionListElement));
                   
                var test = testHarness.addTest('Text/Value Pairs');
                test.addStep(setText('abcd', tb3), checkAutoComplete(10, autoCompleteBehavior3._completionListElement), 50, 3000, verifyValues(autoCompleteBehavior3._completionListElement));
               
               
                var test = testHarness.addTest('Initial4');
                test.addStep(testInitialState(autoCompleteBehavior4._completionListElement, tb4));
                        
                var test = testHarness.addTest('TextBox4_CharsLessThanLimit');
                test.addStep(setText('ab', tb4), checkAutoComplete(0, autoCompleteBehavior4._completionListElement), 50, 2000, verifyAutoCompleteBehavior('ab', 0, autoCompleteBehavior3._completionListElement));
               
                var test = testHarness.addTest('TextBox4_Reset1');
                test.addStep(resetTextBox(tb4));
                test.addStep(testInitialState(autoCompleteBehavior4._completionListElement, tb4));
                           
                var test = testHarness.addTest('TextBox4_CharsEqualToLimit')
                test.addStep(setText('abc', tb4), checkAutoComplete(5, autoCompleteBehavior4._completionListElement) , 50, 2000, verifyAutoCompleteBehavior('abc', 5, autoCompleteBehavior4._completionListElement));
                               
                var test = testHarness.addTest('TextBox4_Reset2');
                test.addStep(resetTextBox(tb4));
                test.addStep(testInitialState(autoCompleteBehavior3._completionListElement, tb4));           
               
                var test = testHarness.addTest('TextBox4_CharsGreaterThanLimit');
                test.addStep(setText('abcd', tb4), checkAutoComplete(5, autoCompleteBehavior4._completionListElement) , 50, 2000, verifyAutoCompleteBehavior('abcd', 5, autoCompleteBehavior4._completionListElement));
               
                var test = testHarness.addTest('TextBox4_Reset3');
                test.addStep(resetTextBox(tb4));
                test.addStep(testInitialState(autoCompleteBehavior4._completionListElement, tb4));
               
                var test = testHarness.addTest('TextBox4_NoDelimetersInList');
                test.addStep(setText('abcd,djshg,agsdj', tb4), checkAutoComplete(5, autoCompleteBehavior4._completionListElement) , 50, 2000, verifyAutoCompleteBehavior('agsdj', 5, autoCompleteBehavior4._completionListElement));
              
                var test = testHarness.addTest('TextBox4_Reset4');
                test.addStep(resetTextBox(tb4));
                test.addStep(testInitialState(autoCompleteBehavior4._completionListElement, tb4));
            }
        </script>
    </asp:Content>

    2009年4月14日 11:22
  • 各位高手一定要帮我找出这个原因,不然心里 感觉很郁闷呀!!
    2009年4月14日 11:23
  • 都来看看呀
    2009年4月15日 10:33
  • 各位高手一定要帮我找出这个原因
    2009年4月15日 11:19
  • 你的程序不全,我认为可以从以下方面着手:
    1,确保asmx这个webservice返回i正确格式的值
    2,undefined说明有不存在的变量或者,如果是你自己写的代码,建议将每一个关键步骤进行输出调试信息
    3,网页加载是顺序要求的,尤其是对象引用,则需要在页面完全加载完毕后进行。
    4,如果嵌套进母版页文件,则客户端的id需要采用服务器对象的ClientID来获取

    可以在这几方面进行调试
    孟宪会
    2009年4月16日 1:06
    版主