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

Get auto complete return value

6 Answers 350 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 17 Jan 2014, 06:56 PM
I got but the autocomplete working but unlike my ajxtoolkit autocomplete I can't get the value the same wa it seems even though they appear to be similar.  Need to the the value to pass onto a hidden field and also pass ontot he code behind to fill the page.

<script type="text/javascript">
        function requesting(sender, eventArgs) {
            var context = eventArgs.get_context();
            //Data passed to the service.
            context["ClientData"] = "ClientData_Passed_To_The_Service";
           // var val = eventArgs.get_value();
        }
    </script>
 
When I put in the line to get the value the service stops working, according to documentation this is how to get value but i think I am doing wrong.  How do I fix this.. Thank you

<telerik:radautocompletebox  ID="rdSearch" runat="server" EmptyMessage="Type Last Name First Name" EnableAutoComplete="true" MinFilterLength="2" MaxResultCount="20" Width="260px"
                                   OnClientRequesting="requesting" DropDownHeight="100px" DropDownWidth="250px" DropDownPosition="static">
                                   <TextSettings SelectionMode="Single" />
                                   <WebServiceSettings Path="../AutoComplete.asmx" Method="GetNames" />
                               </telerik:radautocompletebox>

































6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jan 2014, 06:44 AM
Hi Kevin,

I guess you want to access the text typed in RadAutoCompleteBox on OnClientRequesting event. Please have a look into the following code snippet which works fine at my end.

JavaScript:
<script type="text/javascript">
    function requesting(sender, eventArgs) {
        var context = eventArgs.get_context();
        var hidden = document.getElementById("HiddenField1");
        hidden.value = context.Text;
    }
</script>

Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
0
Kevin
Top achievements
Rank 1
answered on 21 Jan 2014, 01:56 PM
HI,

I does not work for me, the service stop s working and doe4s not return anything.  If I use the following code the service returns fine.  But I need to get a the value that is returned not the text.

This code works fien and the service starts returning itself tot he text box.
function requesting(sender, eventArgs) {
          var txt = eventArgs.get_context();
          //Data passed to the service.
          txt["ClientData"] = "ClientData_Passed_To_The_Service";
      }


But this does not work and the service stops working when I try to get at the value its returning,  It shouold return and ID and text of a persons name.

function requesting(sender, eventArgs) {
          var txt = eventArgs.get_context();
          var PersId = eventArgs.get_value();
          //Data passed to the service.
          txt["ClientData"] = "ClientData_Passed_To_The_Service";
          document.getElementById("<%= HFPersId.ClientID %>").value = PersId;
      }

Above is the same way we do it for our Ajax Control Tool Kit service but the the javscript  client commands are different.

 

OnClientRequesting="requesting"   -Telerik
OnClientItemSelected="SelectedName" - AjAxToolKit

So the question is how can I get at the selected value and do a autopostback event on the autocomplete textbox so that I can hit a database and pull values.

Thank you

 





































0
Kevin
Top achievements
Rank 1
answered on 21 Jan 2014, 08:59 PM

ok,

New to C# used to Vb way of doing things, figured out how to do the OntextChanged event in the code behind but I am getting nothing from the service and also do not see the actual autocomplete box post back either.  My issue above still is the same to get at the value but also the autocomplete text box does not seem to post back.


<telerik:radautocompletebox  ID="rdSearch" runat="server" EmptyMessage="Type Last Name First Name" EnableAutoComplete="true" MinFilterLength="2" MaxResultCount="20" Width="260px"
                                   OnClientRequesting="requesting" DropDownHeight="100px" DropDownWidth="250px" DropDownPosition="static" AutoPostBack="true" OnTextChanged="rdSearch_TextChanged">
                                   <TextSettings SelectionMode="Single" />
                                   <WebServiceSettings Path="../AutoComplete.asmx" Method="GetNames" />
                               </telerik:radautocompletebox>
 
 
 
 function requesting(sender, eventArgs) {
           var context = eventArgs.get_context();
           //Data passed to the service.
          // context["ClientData"] = "ClientData_Passed_To_The_Service";
           var PersId = document.getElementById("<%= HFPersId.ClientID %>")
           PersId.value = context.value
           var lbl = document.getElementById("<%= lblTest.ClientID %>")
           lbl.value = PersId.value
       }
 
 
protected void rdSearch_TextChanged(object sender, AutoCompleteTextEventArgs e)
   {
       HFPersId.Value = lblAttchUic.Text;
       lblUic.Text = "Postback Happened";
   }


0
Nencho
Telerik team
answered on 24 Jan 2014, 09:31 AM
Hello Kevin,

The default InputType of the RadAutoCompleteBox is Token and in a Token scenario the TextChanged event could not be fired. I would suggest you to explicitly set the InputType to Text and use the  TextChanged event handler, in order to get the Entry's value in the following manner for example :

protected void rdSearch_TextChanged(object sender, Telerik.Web.UI.AutoCompleteTextEventArgs e)
    {
        string value = rdSearch.Entries[0].Value;
    }


Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Kevin
Top achievements
Rank 1
answered on 24 Jan 2014, 01:52 PM
hi,

Still no joy, It does not do a postback on the textchanged event, just do not think this control works like the ajaxcontroltoolkit variant which is much easier to use and get at both values.  It seems as if this control is over complicated.  Got this working using the radcombobox but it is just not as clean looking as a textbox option. 
0
Nencho
Telerik team
answered on 29 Jan 2014, 09:41 AM
Hello Kevin,

I had performed further tests locally and it seems that the TextChanged event is correctly triggered. I prepared a sample project for you, demonstrating the behavior at my end. In addition, here is a video on the matter. Could you give it a try at your end and let us know the results?

Note : DLL files are removed from the attachment.

Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
AutoCompleteBox
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or