This is a migrated thread and some comments may be shown as answers.

Parameters for WebServiceSettings Method

5 Answers 456 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Mickael
Top achievements
Rank 1
Mickael asked on 11 Oct 2014, 07:03 PM
Hi,
I am adding RadAutoCompleteBox dynamically to my page.
The autocompleteboxes are using a PageMethod to get the results for the dropdown.
Each autocompletebox is related to a different type, but I cannot implement a search function for each type because these are dynamic too.
I know the Type-autocompletebox relation, but I cannot differentiate them in the PageMethod.
Is there a way to pass a parameter to the PageMethod through the WebServiceSettings of the AutoCompleteBox ?

I tried to use the OnClientDropDownOpening client event, but it is fired after the search completed, so it is too late already.

5 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 14 Oct 2014, 08:25 AM
Hello Mickael,

You could use the OnClientRequesting client-side event of the RadAutoCompleteBox, in order to use the context and pass any custom parameters to the WebMethod. Please consider the below implementation :

javascript
<script type="text/javascript">
       function OnClientRequesting(sender, args) {
           var context = args.get_context()
           context["CustomParam"] = "CutomValue";
       }
   </script>

code-behind
[WebMethod]
   public static AutoCompleteBoxData GetCompanyNames(RadAutoCompleteContext context)
   {
       string CustomParamValue = context["CustomParam"].ToString();


Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mickael
Top achievements
Rank 1
answered on 14 Oct 2014, 12:47 PM
I am trying to use the OnClientRequesting, but it looks like I am doing something wrong because it is not firing
This is what I have so far:

_autoCompleteBox = new RadAutoCompleteBox();
_autoCompleteBox.ID = String.Format("Extra_RdtCmpltBx_{0}_{1}", TypeData.Name, ID);
_autoCompleteBox.Filter = RadAutoCompleteFilter.StartsWith;
_autoCompleteBox.DropDownPosition = RadAutoCompleteDropDownPosition.Automatic;
_autoCompleteBox.AllowCustomEntry = true;
_autoCompleteBox.InputType = RadAutoCompleteInputType.Text;
_autoCompleteBox.OnClientRequesting = "OnClientRequesting";
_autoCompleteBox.WebServiceSettings.Method = "GetResultsByType";
_autoCompleteBox.WebServiceSettings.Path = "Popup_Add.aspx";
_autoCompleteBox.TextSettings.SelectionMode = RadAutoCompleteSelectionMode.Single;
_autoCompleteBox.Entries.Add(new AutoCompleteBoxEntry(Name));

function OnClientRequesting(sender, args) {
    debugger;
    var context = args.get_context()
    context["CustomParam"] = "CutomValue";
}

[WebMethod]
public static AutoCompleteBoxData GetResultsByType(RadAutoCompleteContext context)
{
    string searchString = context["Text"].ToString();
 
    string CustomParamValue = context["CustomParam"].ToString();
}

0
Nencho
Telerik team
answered on 15 Oct 2014, 06:45 AM
Hello Mickael,

I have created a runnable sample for you, demonstrating the implementation of the previous suggested approach. You can give it a try at your end and let us know if the issue still persist.

Note : dll files are removed from the attachment.

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mickael
Top achievements
Rank 1
answered on 15 Oct 2014, 12:14 PM
Thanks, it works now
0
sun
Top achievements
Rank 1
answered on 10 Mar 2015, 10:30 AM
Hello Mickael,
I alse download Nencho's .zip,but it has same problem.I do not know why?Can you help me?
Tags
AutoCompleteBox
Asked by
Mickael
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Mickael
Top achievements
Rank 1
sun
Top achievements
Rank 1
Share this question
or