Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

Last post 09-26-2008 4:34 AM by benbawden. 14 replies.

Sort Posts:

  • Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    05-28-2006, 10:17 PM
    • Participant
      1,852 point Participant
    • webswapp
    • Member since 04-05-2006, 4:08 PM
    • Vancouver, BC, Canada
    • Posts 321

    There were some posts asking for modifying the AutoComplete behavior to accept parameters.  I developed a customized class (by modifying the existing AutoCompleteBehavior class) to allow for parameters passing from one TextBox (that has AutoComplete behavior) to another.  This can be useful in replacing Cascading DropDown lists where the user prefers to type in and tab off instead of selecting from a dropdown list.

    I named this class Sys.UI.CascadingAutoCompleteBehavior

    You can view the demo and the source code in this link:

    http://www.webswapp.com/codesamples/aspnet20/atlas/cascading_autocomplete.aspx

     

    Regards,
    Phillip Williams,
    MCITP Database Developer 2008
    MCPD Web Developer
    MCTS Windows Communication Foundation
    http://www.webswapp.com
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    05-29-2006, 8:39 PM

    Very cool control :)

    But... Perhaps your page has a complex set of rules that should dictate how the auto complete behavior should function. The ability to pass parameters helps, but I think the real problem stems from the fact that the webservice is so isolated from the page containing the textbox. You wouldn't need to pass parameters if you could handle providing the auto complete items as an event on the page.

    So I have created a SmartAutoCompleteExtender that uses a Callback rather than Webservice to get the completion items. This allows you to hook into an event on the extender control - on the same page - to provide the completion items. That way you can incorporate any type of complex logic you can dream up of, because you have complete access to all the other controls on the page like you normally would on a postback. No need to pass any verbose parameters!

    All the details on it and source code at on my blog. Permalink: http://infinitiesloop.blogspot.com/2006/05/atlas-smart-auto-completion.html

     

    End the confusion.
    Infinities Loop: TRULY Understanding ViewState
    .NET from a new perspective.

    This posting is provided "AS IS".
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    05-30-2006, 2:45 AM
    • Participant
      1,852 point Participant
    • webswapp
    • Member since 04-05-2006, 4:08 PM
    • Vancouver, BC, Canada
    • Posts 321

    Hi Dave, 

    Thanks for sharing this code.  I downloaded it and looked through the code (though for some reason the I could not open the solution file using VS2005; I get an error that "This Project type is not supported by this installation").  But I can examine all of the code files. 

    Thanks a lot.

    Regards,
    Phillip Williams,
    MCITP Database Developer 2008
    MCPD Web Developer
    MCTS Windows Communication Foundation
    http://www.webswapp.com
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    05-30-2006, 3:03 AM

    Oops, right, I should mention that the project type is this:

    http://webproject.scottgu.com/

     

    End the confusion.
    Infinities Loop: TRULY Understanding ViewState
    .NET from a new perspective.

    This posting is provided "AS IS".
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    06-07-2006, 3:37 PM
    • Member
      95 point Member
    • ethos42
    • Member since 07-09-2003, 3:10 AM
    • Posts 21

    InfinitiesLoop: I downloaded your source code and got the basic exmple to work, but I can't see how I would get it to change the results based on a contol on the page.

    I added a radiobutton list with 2 items with the text/values set to 1 and 2 (to keep it simple) and then in the eventhandler code on the backend I simpy added this to the return value:

    args.CompletionItems = new string[] { prefix + this.RadioButtonList1.SelectedValue + "A", prefix + this.RadioButtonList1.SelectedValue + "B", prefix + this.RadioButtonList1.SelectedValue + "C" };

     Unfortunatly, it does not show any change in the output. I don't think it is reading the new state of the radiobuttonlist. Any suggestions?

  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    06-07-2006, 10:23 PM

    Well, unfortunately callbacks arent a fully glorified postback like I originally thought. Only certain data is posted, and the values of postback controls is not included. That means the data you try to get off of the other controls on the page will represent their state as of the last postback, not as of the callback. So the quick workaround is to just enable AutoPostBack on the radiobutton list. That way the server is always up to date with the selected value when the callback occurs. Same goes for textboxes, dropdowns, etc.

    I didn't realize this limitation when I created the control, and it seemed to work because I had happened to be performing postbacks inbetween. I'm going to have to think about a better solution, perhaps somehow causing a full blown out of band postback instead of the lightweight callback. Hmmm.

     

    End the confusion.
    Infinities Loop: TRULY Understanding ViewState
    .NET from a new perspective.

    This posting is provided "AS IS".
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    06-08-2006, 1:32 AM

    Ah ha... I have a solution!

    What I didn't realize is that asp.net calls a WebForm_InitCallback function at the beginning of the page load (on the client). It creates all the postback data that will be needed if there is to be a callback. However, because it is called at the beginning, it will not represent all the data the user enters into the various form fields afterwards.

    By calling WebForm_InitCallback() manually again, just before doing the callback, the post data is recreated and the correct values are visible on the server. Perfect.

    I will be putting together a fix for it and posting it on my blog shortly. I will also put in a sample page using the functionality, with a RadioButtonList.

    Thanks for the bug report and thanks for trying it out :)

    End the confusion.
    Infinities Loop: TRULY Understanding ViewState
    .NET from a new perspective.

    This posting is provided "AS IS".
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    06-08-2006, 12:58 PM
    • Member
      95 point Member
    • ethos42
    • Member since 07-09-2003, 3:10 AM
    • Posts 21

    Thats great! I appreciate the quick response and can't wait to see the update. I'm hoping to use this in a project that has to filter out 78k records (currently done by using 2 dropdowns and is insanly slow bleh)

    Since I have your attention :) I was wondering if you could point me in the right direction on how to modify the apperance of the autocomplete list. At first I think just changing the styles would be ok, but I'd like to digg deeper into the actual format (I'm not very happy with the way the div's are set to the same length of the textbox even though the returned text may be much longer)

  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    06-08-2006, 1:14 PM
    • Member
      5 point Member
    • AtlasHelp
    • Member since 06-08-2006, 5:10 PM
    • Posts 1

    By calling WebForm_InitCallback() manually again, just before doing the callback, the post data is recreated and the correct values are visible on the server. Perfect.

    I will be putting together a fix for it and posting it on my blog shortly. I will also put in a sample page using the functionality, with a RadioButtonList.


    Please post when the fix is done on your blog.  Interested to see how this works.

     

    Thanks

  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    06-08-2006, 11:18 PM

    The fix is now available... read the update paragraph at the bottom of the post for details: http://infinitiesloop.blogspot.com/

    I also threw in a sample web application that is using the SmartTextBox. It contains a RadioButtonList, and the suggestions vary based on its selected index.

    End the confusion.
    Infinities Loop: TRULY Understanding ViewState
    .NET from a new perspective.

    This posting is provided "AS IS".
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    06-08-2006, 11:27 PM
    ethos42:

    Since I have your attention :) I was wondering if you could point me in the right direction on how to modify the apperance of the autocomplete list. At first I think just changing the styles would be ok, but I'd like to digg deeper into the actual format (I'm not very happy with the way the div's are set to the same length of the textbox even though the returned text may be much longer)

    Well, my custom behavior is really just reusing the built in behavior. The beauty was I didn't even have to try to understand how it works or how it builds the autocompletion region. I would have to look into it in more detail to figure how how I could accomplish that. I would imagine it would be possible to expose a AutoCompleteStyle property which would be a standard asp.net style object. The style could render as an attribute on the script node, and so the behavior could assign it to the div it creates. Then you could control what it looks like just like any other asp.net control, including its width.

    I don't know if I'll have time to do that any time real soon, but I'll keep it in mind :) Thanks.

    End the confusion.
    Infinities Loop: TRULY Understanding ViewState
    .NET from a new perspective.

    This posting is provided "AS IS".
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    02-06-2008, 4:36 AM
    • Member
      12 point Member
    • ibtesam_bloch
    • Member since 02-27-2007, 5:11 AM
    • Posts 6

    hi infinties loop,

    i had been using ur control since longtime..and i agree its awesome. recently i got a requirement where i had to output the list on the panel. the height being less and the space being small i was compelled to use a scroll on result panel. the problem is the scrolls appear fine in IE but in firefox it doesnt appear atall.adding to it the results are trimmed based on the height of the panel ...please help :(

  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    02-06-2008, 1:20 PM

    Can you post some code?

    End the confusion.
    Infinities Loop: TRULY Understanding ViewState
    .NET from a new perspective.

    This posting is provided "AS IS".
  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    02-15-2008, 2:20 AM

    Hi InfinitiesLoop,

    I've used your SmartAutoCompleteExtender, and its fantastic. But according to last update in AutoCompleteExtender, some properties like OnClientItemSelected, etc. have been added and which helps me to carry out some functionality on client-side needed while say selection of an item from the suggestion list.

    This works fine with AutoCompleteExtender provided in AjaxControlToolkit, but somehow when I'm using it with SmartAutoCompleteExtender, it does not get fired. Can you please help me with this?!

    Thanks in advance.

  • Re: Cascading AutoComplete customized behavior built from the existing AutoCompleteBehavior

    09-26-2008, 4:34 AM
    • Member
      77 point Member
    • benbawden
    • Member since 05-19-2004, 3:22 AM
    • Posts 23

     Did you ever manage to get the onclientitemselected event to fire? I'm trying to use this control, and need to separate a key and a value into 2 different controls.

     Thanks

Page 1 of 1 (15 items)