Creating custom controls, having difficulty incorporating AJAX into them. RRS feed

  • Question

  • User-2126857960 posted


    I hope I posted this in the correct place.

    Basically my goal is to create a custom control that has an Ajax AutoCompleteExtender and textbox field in it. This way, all I got to do is place this control throughout my projects, and all of the background stuff is nice and neat (e.g. the database queries to retreive the lists, as well as the .ascx code is all in one place).

    I have done similar things like this with other controls, but none of which had an AJAX field in it. Everything compiles and runs fine, and the textbox is displayed properly, but when you type in stuff, nothing ever happens (I tested this code already under normal circumstances and not in a control and it works just fine). 

    The AutoCompleteExtender uses a webservice, and I'm wonder if maybe its not able to reach or call it? It seems this is the root of the problem. I placed the web service in the same folder as the control, and created it just like the tutorial (link is below).

    Here is the AutoCompleteExtender tutorial I followed and my code is pretty much just like it: http://www.codeproject.com/Articles/201099/AutoComplete-With-DataBase-and-AjaxControlToolkit

    If I could get some help or advice that would be greatly appreciated, thank you!

    Thursday, May 17, 2012 10:43 AM

All replies

  • User1100692814 posted

    Hi Mahonroy,

    You cannot call a WebMethod through a user control because it will be automatically rendered inside the page. Move your web method to your  ASPX page.

    If you want the logic inside the controller then you can call it from ASPX page but your web method needs to be in the ASPX page.

    According to Dino Esposito in MSDN Magazine Feb 2007:

    "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."


    I hope this helps.


    Tuesday, November 17, 2015 4:55 AM