locked
Unable to get property 'webServiceFailedNoMsg' of undefined or null reference RRS feed

  • Question

  • User2107475791 posted

    hello,

    I am using a AutoCompleteExtender when I try to run it I get an error, 'Unable to get property 'webServiceFailedNoMsg' of undefined or null reference' when it try to call it's service methods, here my code below. The service method is used to pull a list of patient last name from the databased based on what the user typed in.

    My UI code.

    <asp:TextBox ID="txtLastName" runat="server" Width="250px" />
    <ajaxToolkit:AutoCompleteExtender runat="server" ID="aceLastName" TargetControlID="txtLastName"
            ServiceMethod="GetLastNameCompletionList" ServicePath="../UiHelper/PatientServiceForAutoSuggest.asmx"
            MinimumPrefixLength="2" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20" DelimiterCharacters=";, :">
        </ajaxToolkit:AutoCompleteExtender>

    Service Method: PatientServiceForAutoSuggest.asmx

    /// <summary>
        /// Summary description for PatientServiceForAutoSuggest
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class PatientServiceForAutoSuggest : System.Web.Services.WebService
        {
            private Guid _UserID;
    
            [System.Web.Services.WebMethod]
            [System.Web.Script.Services.ScriptMethod]
            public string[] GetFirstNameCompletionList(string prefixText, int count, string contextKey)
            {
                List<string> lst = new List<string>();
    
                try
                {
                    _UserID = (Guid)Session["_UserID"];
    
                    DataTable patients = UserFacadeAccess.MCLUserInactivePatientsSelect(_UserID);
    
                    foreach (DataRow row in patients.Rows)
                    {
                        if (!lst.Contains(MCLCommon.MCLCommonObject.CaseRules.ApplyCases(row["FirstName"].ToString())))
                        {
                            lst.Add(MCLCommon.MCLCommonObject.CaseRules.ApplyCases(row["FirstName"].ToString()));
                        }
                    }
                }
                catch (Exception ex)
                {
                    CommonFacadeAccess.LogError(ex, _UserID);
                }
    
                return lst.ToArray();
            }
    }

    Monday, December 5, 2016 6:19 PM

Answers

All replies

  • User-6180675 posted

    There is a mismatch between the servicemethod name in the extender control and in the actual web service. In the extender you have mentioned servicemethod as below

    awaredoc

    ServiceMethod="GetLastNameCompletionList"

    but in your asmx web service the method name is different as seen below

    [System.Web.Services.WebMethod] 
    [System.Web.Script.Services.ScriptMethod] 
    public string[] GetFirstNameCompletionList(string prefixText, int count, string contextKey)  

    This might be why the extender is not able to find the service method and returning null reference.

    Also the servicemethod signature should be like below as per the documentation

    public string[] GetFirstNameCompletionList(string prefixText, int count)
    
    OR
    
    public string[] GetLastNameCompletionList(string prefixText, int count)

    // and you should be using prefixText to search in the database like below

    if (!lst.Contains(MCLCommon.MCLCommonObject.CaseRules.ApplyCases(prefixText.ToString()))) 
    {
    lst
    .Add(MCLCommon.MCLCommonObject.CaseRules.ApplyCases(prefixText.ToString()));
    }

    P.S : I also forgot to mention that if you need to call web service method from ASP .NET AJAX then you need to uncomment the below lines of code

    // [System.Web.Script.Services.ScriptService]

    Hence there are several issues in your code. Let me know if it works after making the changes.

    Monday, December 5, 2016 6:36 PM
  • User283571144 posted

    Hi awaredoc,

    I am using a AutoCompleteExtender when I try to run it I get an error, 'Unable to get property 'webServiceFailedNoMsg' of undefined or null reference' when it try to call it's service methods, here my code below.

    According to your description, I suggest you could firstly try to uncomment this line:

    This method could allow the Web Service to be called from script, using ASP.NET AJAX.

          // [System.Web.Script.Services.ScriptService]

    Besides, as Nilishere says, the autocomplete control ServiceMethod is not the method you post.

    If my solution isn't solve your issue, I suggest you could post more relevant codes about the webmethod.

    Best Regards,

    Brando

    Tuesday, December 6, 2016 6:34 AM
  • User-6180675 posted

    I just tested with a similar code in my system ... it works perfectly for me even though I got the javascript alert while debugging sometimes but the autocomplete works well after making the changes I mentioned above. Please note that you can only pass extra parameters like "ContextKey" in the service method only if the "UseContextKey" property of the extender is set as true.

    Please refer to the below link :

    http://www.aspsnippets.com/Articles/ASPNet-AJAX-AutoCompleteExtender-Pass-Additional-Parameter-to-WebMethod-using-ContextKey.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 6, 2016 6:12 PM