0

I have created a user control, in which I plan to use every time the user edits certain content and a regular ASPX page where I call the user control. The user cotrol contains a few textbox and an AutoCompleteExtender. Everything works fine except the Extender. I've used it in many other APSX pages and worked like a charm, but for some reason it doesn't seem to work here. After debugging, through chrome, I found out that I don't have access to the method(405). After a few days of scavenging, the internet, I found this:

"A callable page method is a public static (or Shared in Visual Basic® .NET) method defined in the codebehind class and decorated with the same WebMethod attribute used for Web service methods. At present, this is limited to ASPX pages-both inline and codebehind code-but might be extended in the future to user controls and custom controls."

Also, stumbled upon other forums suggesting a web service instead of a web method. Tried this and still got the same (405) error. I've being stuck for almost a week and I've ran out of options. Is this a bad practice and that's why you can't do it? All I want is to keep it all on the same user control and aspx.

This is how I'm using the extender on my user control:

<aspx:AutoCompleteExtender ID="tbEntitiesAutoCompleteEx" runat="server"
      BehaviorID="tbEntitiesAutoCompleteEx" TargetControlID="tbEntity"
      UseContextKey="True" ServiceMethod="GetAutocompleteEntities"
      MinimumPrefixLength="3" CompletionSetCount="10" CompletionInterval="300"
      CompletionListCssClass="autoCompleteList"
      CompletionListItemCssClass="autoCompleteItem" 
      CompletionListHighlightedItemCssClass="autoCompleteHighlightedItem"       
      CompletionListElementID="divCodeAutoCompletePlacement"  
      OnClientPopulating="OnEntitiesPopulating" 
      OnClientPopulated="OnEntitiesPopulated" 
      OnClientItemSelected="OnEntitySelected"                                
      ShowOnlyCurrentWordInCompletionListItem="true" 
      FirstRowSelected="true" ServicePath ="~/InterventionsWebService.asmx" />

I've changed the service path to ~/InterventionsWebService.asmx(web service in the same directory), CreateEdit.aspx(page I call user control) and CreateEdit.ascx(user control it's self) and none worked.

This is the web Method:

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public List<string> GetAutocompleteEntities(string prefixText, int count, string contextKey)
{
    var bbq = 0

    return new List<string>();
}

I've also tried making it into a static method but still not working. I have a break point on var bbq = 0 but it never hits due to the (405) error. Any explanation would be nice, thanks.

2 Answers2

0

I managed to fix my problem. I removed the service path, placed the web method in the aspx where the ascx is being called, made the web method static and managed to hit the break point.

0

I put the WebMethod on the webpage and used it to call a method on the UserControl.

Dr T
  • 504
  • 1
  • 7
  • 20