Property value undefined after succesfull web service call

Last post 01-18-2007 8:27 PM by RhythmAddict112. 4 replies.

Sort Posts:

  • Property value undefined after succesfull web service call

    01-09-2007, 9:19 AM
    • Loading...
    • huygens
    • Joined on 11-03-2006, 8:08 AM
    • Posts 12

    Hello,

    hopefully I can explain my problem.

    I started to create extended control with ajax control toolkit. Idea is, that I have textfield which works so

    that it suggest values every time when user hits key. Like that --> http://www.google.com/webhp?complete=1&hl=en

    Now in SearchTextBoxBehavior.js file I have two propertys, which one hold id for listbox which shows suggestions.
    (I think in that google example, the control is span or div element.)

     
    Ok, I have succesfully created event, which is occurred when user hits key in textfield. Webservice call is made in bold code line-->

     

    1    _onkeyup : function() {
    2 3 var targetButton = $get(this._TargetButtonID);
    4 var targetListBox = $get(this._TargetListBoxID);
    5
    6 if(targetButton && targetListBox) {
    7 targetButton.disabled = true;
    8
    9 // unescape() convert´s a string to URL-encoded form 10 var searchValue = unescape(this.get_element().value);
    11
    12 if(searchValue != "") {
    13 // Set suggestion visible 14 targetListBox.style.visibility = "visible";
    15
    16 MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue, this._onSucceeded);
    17 }
    18 else {
    19 // Set suggestion hidden when there is no search value inserted 20 targetListBox.style.visibility = "hidden";
    21 }
    22 }
    23
    24 },
      
     
    Web service call is succesfull, and returns into function:
     
    1    _onSucceeded : function(Result) {
    2    
    3    var targetListBox = $get(this._TargetListBoxID);
    4    
    5    var table = Sys.Preview.Data.DataTable.parseFromJson(Result);
    6    
    7    ....
    8    
    9    }
     
    Problem is, that in that _onSucceeded function, property this._TargetListBoxID is
    undefined. In function, where I made web service call, the property was ok, and I could
    make instance about control. 
     
      
     

     
  • Re: Property value undefined after succesfull web service call

    01-10-2007, 2:48 AM
    • Loading...
    • Garbin
    • Joined on 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,494
    • TrustedFriends-MVPs

    Hi,

    you need to modify the context under which the callback is executed. This can be done with a delegate and the Function.createDelegate method:

    MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue, Function.createDelegate(this, this._onSucceeded));


     

    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: Property value undefined after succesfull web service call

    01-10-2007, 3:08 AM
    • Loading...
    • huygens
    • Joined on 11-03-2006, 8:08 AM
    • Posts 12

    Hi,

    it worked, thanks. :)


    Yesterday evening I managed to circulate problem, with solution below.

     

    1    var inputParams = new Array();
    2    inputParams[0] = this._TargetListBoxID;
    3    inputParams[1] = this._TargetButtonID;
    4    inputParams[2] = this._ListControlTextField;
    5    inputParams[3] = this._ListControlValueField;
    6    
    7    MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue, this._onSucceeded, this._onFailed, inputParams); 
    
     
  • Re: Property value undefined after succesfull web service call

    01-10-2007, 3:57 AM
    • Loading...
    • Garbin
    • Joined on 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,494
    • TrustedFriends-MVPs

    Hi,

    yes, as your code shows, you're passing a context object as the last parameter to the proxy method. This is useful especially if you want to access only certain references in the callback and not the whole instance.

    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: Property value undefined after succesfull web service call

    01-18-2007, 8:27 PM

    Hi All,

    huygens...is there any way you can post your full code?  I'm looking to do something similar with the toolkit.  Would be greatly appreciated.

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter