Reputation: 708
I am working with the Ajax control kit to add an autocomplete to my search textbox. I cannot get it to work using a PageMethod or a webservice on my masterpage. I was able to create a new page not using a masterpage and it worked. Here is my code.
Edit- I found out Page-Method does not work in a masterpage. I am still having trouble calling the web service though. I add a service refrence to it then add this to the extender "ServicePath="NameWebService.asmx"" I still get nothing. I check to see if the server side is getting hit and it is not.
<asp:ScriptManager ID ="ScriptManager2" EnableCdn="true" LoadScriptsBeforeUI="false"
runat="server" EnablePageMethods="true" />
<asp:Panel ID="pnlSearch" runat="server" DefaultButton="btnSearch">
<asp:TextBox ID="txtSearch" CssClass="textbox" placeholder="User Name/ Full Name"
runat="server" Width="200px" AutoComplete="off" />
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
TargetControlID="txtSearch" ServiceMethod="GetSearchResult"
MinimumPrefixLength="2" />
<asp:Button ID="btnSearch" runat="server" CssClass="buttonSubmit" Text="Search"
onclick="btnSearch_Click" />
</asp:Panel>
This is my page method
[System.Web.Services.WebMethod]
public static string[] GetSearchResult(string prefixText, int count)
{
List<Person> listPerson = Person.SearchForPerson(prefixText);
string[] arrayNames = listPerson.Select(n => n.FullName).Take(count).ToArray();
AbuseReport report = new AbuseReport();
report.AbuserPersonID = -1;
report.Message = prefixText;
report.ReportingPersonID = -1;
report.CreateAbuseReport();
return arrayNames;
}
This is my webservice
[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 NameSearch : System.Web.Services.WebService
{
[WebMethod]
public string[] GetSearchResult(string prefixText, int count)
{
List<Person> listPerson = Person.SearchForPerson(prefixText);
string[] arrayNames = listPerson.Select(n => n.FullName).Take(count).ToArray();
AbuseReport report = new AbuseReport();
report.AbuserPersonID = -1;
report.Message = prefixText;
report.ReportingPersonID = -1;
report.CreateAbuseReport();
return arrayNames;
}
} // End of Service
Upvotes: 0
Views: 315
Reputation: 711
You probably need to register your Webmethod in the web.config
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://www.yourdomain.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service name="Service">
<endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Service"/>
</service>
</services>
<bindings>
</system.serviceModel>
See "How to: Use Configuration to Add an ASP.NET AJAX Endpoint" at http://msdn.microsoft.com/en-us/library/bb628467.aspx
Upvotes: 1