How to call a method of ASP.NET AJAX control ?

Last post 10-29-2009 12:43 PM by slishnevsky. 2 replies.

Sort Posts:

  • How to call a method of ASP.NET AJAX control ?

    10-28-2009, 6:20 PM
    • Member
      41 point Member
    • slishnevsky
    • Member since 01-02-2003, 7:36 AM
    • Posts 172

    Hi,

    I have created a control, I associate my control with a DIV element

    function pageLoad() {

        $create(Homepage.Autocomplete, null, null, null, $get("Test"));

    }

    <div id="Test"></div>

    The control's name is Autocomplete, and it has a public method (function): load(text, count){} that calls WebService method.

    My question: How do I call that load(text, count) method from javascript on my page?

    function foo() {

         Homepage.Autocomplete.load("some text", 10);

    }

    it doesn't work. Debugger sees Homepage.Autocomplete, but when I mouse over "load", it shows undefined.

    Any idea how to do that correctly?

    Thanks.



    Below is the code for the control Autocomplete.js (I cleaned it for sake of simplicity):


    Type.registerNamespace("Homepage");

    Homepage.Autocomplete = function(element) {
        Homepage.Autocomplete.initializeBase(this, [element]);
    }

    Homepage.Autocomplete.prototype = {
        initialize: function() {
            Homepage.Autocomplete.callBaseMethod(this, "initialize");
        },
        dispose: function() {
            Homepage.Autocomplete.callBaseMethod(this, "dispose");
        },
        load: function(text, count) {
            WebService.GetSuggestions(text, count, this.oncompleted, this.onfailed, this);
        },
        oncompleted: function(data, control) {
        },
        onfailed: function(error, control) {
        }
    }
    Homepage.Autocomplete.registerClass("Homepage.Autocomplete", Sys.UI.Control);

    if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();




  • Re: How to call a method of ASP.NET AJAX control ?

    10-28-2009, 10:53 PM
  • Re: How to call a method of ASP.NET AJAX control ?

    10-29-2009, 12:43 PM
    Answer
    • Member
      41 point Member
    • slishnevsky
    • Member since 01-02-2003, 7:36 AM
    • Posts 172

    Update - had to use:


    var x = $create(Homepage.Autocomplete, null, null, null, $get("Test"));

    x.load("some text", 10);


Page 1 of 1 (3 items)