Monday, March 26, 2012

Property value undefined after succesfull web service call

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

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));



Hi,

it worked, thanks. :)


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

1var inputParams =new Array();2inputParams[0] =this._TargetListBoxID;3inputParams[1] =this._TargetButtonID;4inputParams[2] =this._ListControlTextField;5inputParams[3] =this._ListControlValueField;67MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,this._onSucceeded,this._onFailed, inputParams);

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.


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.

No comments:

Post a Comment