Showing posts with label autocompleteextender. Show all posts
Showing posts with label autocompleteextender. Show all posts

Wednesday, March 28, 2012

Extending the AutoCompleteExtender

Hi,

I'm trying to extend the AutoCompleteExtender so that is also can return an extra (hidden) value. For now I just do this by passing the text and the value returned by the WebMethod just as a comma separated string, i.e. "AnObject;5" (where 5 is the ID of the object). I just started on this so I'm not sure of I'm doing things the way they are supposed too. So here's a question.

I managed to extend the AutoCompleteBehavior javascript so that I can pass the result of the WebMethod to the TextBox and it just shows the text (the value is split of).

I also added an extra property ValueTextBoxId to the Properties of the AutoCompleteExtender to reference the TextBox which should store the hidden value. I have now the correct ClientId of the TextBox in the javascript. Next step is setting the value of that textbox.

I can use $(this.get_valueTextBoxId()).value to set it. But I guess it's more in the ways of Atlas to use the Sys.Ui.TextBox object. Only I cannot find any documentation how I can use that object when I have just a ClientID.

Anybody an idea?

Not sure of the solution to your other issues, but to use the Sys.UI.TextBox with a client id you need only do this.

var AtlasTextBox = new Sys.UI.TextBox($(ClientID));
AtlasTextBox.initialize(); // I can't remember if this line is required or not.

Jay

Extending the AutoComplete extender

I am trying to add more to the functionality of the AutoComplete extender. I would like to write my own and inherit from AutoCompleteExtender.

I would like to add a member variable that will hold the results from the last search ( similar to what the cache does, but just for the last search ) and then at a later point be able to compare a given string a see if it is one of the strings returned from the last search.

I am having trouble with the js. Any help would be appreciated

here is what my js file looks like, but I am not sure how to save the results from the last search.

Type.registerNamespace('CustomAutoCompleteControl');

CustomAutoCompleteControl.CustomAutoCompleteControlBehavior = function(element) {
CustomAutoCompleteControl.CustomAutoCompleteControlBehavior.initializeBase(this, [element]);
}

CustomAutoCompleteControl.CustomAutoCompleteControlBehavior.prototype = {

this._suggestions: null,

clearSuggestions: function() {
this._suggestions = null;
}
}

CustomAutoCompleteControl.CustomAutoCompleteControlBehavior.registerClass('CustomAutoCompleteControl.CustomAutoCompleteControlBehavior', Sys.Preview.UI.AutoCompleteBehavior);


I also created the .cs class and added the ClientScriptResource entry to make reference to the js file.

Do I need to overwrite the _update function, or what should I do to save the results? Any code would be helpful.

Thanks in advance

Looking at the AutoCompleteExtender, the completion list handles the mouseDown and Enter/Tab keypress events and calls a function by the name of setText which sets the textbox.

You may be able to use the existing property _currentPrefix...


_setText: function(text) {
this._timer.set_enabled(false);
this._currentPrefix = text;
var element = this.get_element();
var control = element.control;
// todo: should check for 'derives from' too and should somehow manually cause TB to raise property changed event
if (control && control.set_text) {
control.set_text(text);
}
else {
element.value = text;
}
this._hideCompletionList();
},


I would like to save the suggestions right before they are displayed to the user. There is a method called _update that is called which I think I would need to override, but I am not sure what the correct syntax to overriding a method is with this framework. Do I just rewrite that method the way I want it in my class and it will know to use that version for that method and the parent class' methods for the others? Do I need to override any other methods in order to make it work.

I think I have an idea on what I need to do, but the syntax is holding me back here. Any suggestions are appreciated.


Sorry, I misunderstood the first post. I thought you wanted to save the last finalized choice.

Extend AutoCompleteExtender behavior

I have written the webservcie to parse the prefixText on semicolom ";" (if present) and return completion list based on the character after the semicolon. That works great, however on the client when a value from the completion list is selected, it overwrites the text box contents.

So for first case I type a charcter 'a' and select ASP from the list, then I add ASP;c to the text box and get a completion list with values {"C#","Code"}. On selecting C# it overwrites the contents in the text box, I want it to be ASP;C#

I want to extend this behavior to append the selection from completion list to the contents of the text box in order to implement gmail type functionality.

Has anyoneout there tried to implement the sutocomplete extender this way.

Thanks in advance.

This is an interesting idea that I had not thought about. It should be possible already using my custom auto complete extender (see signature). I raise an event when an item is selected letting you pass back the string that you want in the textbox. I do this because I use objects instead of just strings returned from my website, so I need to be able to pick the text I want to place in the textbox. So, you could handle this event and append the values and pass the entire value back.


Thank you for a prompt reply.

Its possible to send back the whole string to the completion list. So for first search "a" will yield ASP. Adding ASP;c to the text box will have to get {"ASP;C#","ASP;Code"}

This approach might not help if the text is long (like email address) and won't look as if it is enhancing the user experience either. Is there any other way to achieve this.

Thanks Again


Any other ideas how to achieve this.

Is there a way to add this to the enhancement list with the Atlas team?

Any help is appreciated.

Thanks Again.

Wednesday, March 21, 2012

errow message in autocomplete exstention

Just install the toolkit getting this err

"AjaxControlToolkit.AutoCompleteExtender missing required ServiceMethod property value for AutoCompleteExtender1.
Parameter name: ServiceMethod"

What coud be the problem ??

You are missing the WebService that is used in the AutoCompleteExtender. The default AutoCompleteExtender takes GetCompletionList as service method in AutoComplete.asmx. Check you have that file

Thanks


i downlodede the exstention - zip file, where is the web servise ?


If you have downloaded only the extension, then you need to provide the WebSerivce methods.

If you have download the AjaxToolkit, then the web service comes along with that. The source for toolkit is herehttp://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=AtlasControlToolkit

Thanks


DEar Frind

I download it from the same place , install the template created my tab at vs 2005 adn chose the dll from the bin file at the websample ?

What more need i do ?


Post the code you have written for the autocomplete extender

Thanks


hey

The code of the autocomplete

<cc1:AutoCompleteExtenderID="AutoCompleteExtender1"runat="server"TargetControlID="TextBox1"></cc1:AutoCompleteExtender>

- getting exception in the begining of the page loading.

Thank u


If that is your code, then its correct you are getting the error. AutoCompleteExtender needs servicepath and service method from where it can pick the values for the list. Did you see the sample at http://ajax.asp.net/ajaxtoolkit/AutoComplete/AutoComplete.aspx and how it was implemented? Check the autocomplete properties in the link given, and if you open the AutoComplete folder in the SampleWebSite you downloaded, you will see the complete code on how it was implemented.

Thanks


Saw it Ofcourse but canot find the asmx file ?

copy the servise path as wriiten, getting err that canot find the asmx file.


Thnak its works - wrote the hole path.

ScriptPath

="AutoComplete.asmx"TargetControlID="TextBox1"CompletionInterval="12"ServiceMethod="GetCompletionList"

working - thank uBig Smile


If you have downloaded the AjaxControlToolkit properly the asmx file is in

AjaxControlToolkit\SampleWebSite\AutoComplete\AutoComplete.asmx and the corresponding .cs file in the App_Code.

Thanks