Monday, March 26, 2012

ASP.NET AJAX Beta 1 and AutoCompleteExtender

Have follow page:
1<%@dotnet.itags.org. Register TagPrefix="ajaxPreview" Namespace="Microsoft.Web.Preview.UI.Controls" Assembly="Microsoft.Web.Preview" %>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">45<html xmlns="http://www.w3.org/1999/xhtml" >6<head id="Head1" runat="server">7<title>test autocomlete</title>8</head>9<body>10 <script language="javascript">11 function onClick()12 {13 SearchService.GetAutoCompleteList("a",10, function(a1){alert(a1);} );14 }151617 </script>18 <form id="form1" runat="server" defaultfocus="UserNameTextBox">19 <asp:ScriptManager ID="MainScriptManager" runat="server" >20 <Services>21 <asp:ServiceReference Path="~/Services/SearchService.asmx" />22 </Services>23 </asp:ScriptManager>2425 <input type="button" id="btn" value="custom call" onclick="onClick();" />26 <asp:TextBox ID="tbSearch" runat="server" /><br /><br />2728 <ajaxPreview:AutoCompleteExtender ID="extSearchAutoCompleteExtender" runat="server"29 MinimumPrefixLength="1" Visible="true"30 ServicePath="~/Services/SearchService.asmx"31 ServiceMethod="GetAutoCompleteList"32 TargetControlID="tbSearch" />33 </form>34</body>35</html>36

and service:

[WebService][ScriptService]public class SearchService : WebService { [WebMethod] [ScriptMethod(true)]public string[] GetAutoCompleteList(string PrefixText,int count) { ... } }

When i press button - it works. But AutoCompleteExtender not work.
I debug internal JS Code. it seems that Request to server was send in JSON format, but not parsed on server properly, and call not come to Service.
I set breakpoint in service - it never come to it when use AutoCompleteExtender. But in Fiddler i can see that request goes to server.

in Jule CTP same code was works fine.

In anywherein new documentation has sample with AutoCompleteExtender ? how use it in ASP.NET AJAX Beta 1

hello.

it seems like you're using get for the request. try removing true from the scriptmethod and see if it works.


Initialy it was without true, but not work too.

I place true, when try to fix with. By Http Traces this flag not change anything.

I'm found a problem, but not know how to fix it.

when i call service with button follow package was send:

{"PrefixText":"a","count":10}
but when i type "a" in text box: content will be follow:
{"prefixText":"a","count":10}
 and response from server:
 
"@._Error(false,"Invalid web service call, missing value for parameter: \'PrefixText\'."," at Microsoft.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters) at Microsoft.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters) at Microsoft.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams) at Microsoft.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","System.InvalidOperationException")Error_@."
Why in second case parametr prefixText starts with non Capital letter?


if I change Service Method signature form
public string[] GetAutoCompleteList(string PrefixText,int count)

to

public string[] GetAutoCompleteList(string prefixText,int count)
AutoCompleteExtender works fine. But i have no clue why it works so.
Can anyone explain why i need parametrs started from nonCapital letter?

First off... thanks for posting this (along with the solution) as i just ran into that error as well (Fiddler is so great for helping debug, eh)

Anyways, to maybe make an attempt at answering:

mogadanez:

Can anyone explain why i need parametrs started from nonCapital letter?

Perhaps since the "closure" to "prototype" change that capitalization became important? that's just a wild shot in the dark


Just to backup my wild shot in the dark, using fiddler to poke around the javascript files spit out by the ScriptManager it has:

Sys.Net._WebMethod._invoke(this, this._serviceMethod, this._serviceMethod, false,
{prefixText : this._currentPrefix, count: this._completionSetCount },

when i call service method "by hand"

<script language="javascript">
11 function onClick()
12 {
13 SearchService.GetAutoCompleteList("a",10, function(a1){alert(a1);} );
14 }
15
16
17 </script>
...
19 <asp:ScriptManager ID="MainScriptManager" runat="server" >
20 <Services>
21 <asp:ServiceReference Path="~/Services/SearchService.asmx" />
22 </Services>
23 </asp:ScriptManager>

it's work with any parametrs names "PrefixText", "prefixText", and "BLABLA"
It is not work from AutoCompleteExtender ( and maybe from other components )

and i have no idea why.


hello.

that's weird...i've just tested with a simple page and i've named the parameter PrefixText and it works without any problem...


in simple service call? or in AutoCompleteExtender?

mogadanez:

if I change Service Method signature form

public string[] GetAutoCompleteList(string PrefixText,int count)

to

public string[] GetAutoCompleteList(string prefixText,int count)

AutoCompleteExtender works fine. But i have no clue why it works so.

I had the exact same problem and was getting very frustrated by it. This fixed my problem perfectly. Thank you for posting this fix.

Devteam, Can we get updated documentation showing these sorts of updates or atleast some form of example for the AutoCompleteExtender.


Another big thanks here !!!

I thought I was going nuts, how much can go wrong in configuring the autocomplete extender.

changing PrefixText to prefixText was all it took.

Kuddo's !


This problem is true for VB.net also. Thanks for the help.
hello guys. just like to confirm if this behavior happens when you use the internal server or only with iis. thanks.
I am using Localhost with IIS

No comments:

Post a Comment