Showing posts with label listsearch. Show all posts
Showing posts with label listsearch. Show all posts

Monday, March 26, 2012

ListSearch does not preserve ViewState

I just downloaded the latest version of the Toolkit today hoping that the 3 or so issue requests for the ListSearch would have corrected everything.

My problem is that after a item is selected in a DropDownList the and I either hit the tab key or press enter (with the autopostback set on the ddl) the postback occurs (that part was fixed from the last version) but when the page comes back the ddl is reset. It does not contain the item I selected even though enableviewstate is set to true. Does anyone else have this problem or know how to correct it?

Thanks

I've just run a small test and it worked fine for me -- if you change the item simply by clicking, does the selected item remain?

Thanks,

Damian


FWIW if you try enabling the AutoPostBack on the example in the toolkit, then it won't work because the control's contents are always rebound on page load, instead of just once when the page is initially loaded.

Regards,

Damian (ListSearch author)


No it does not, I have tried it both in a update panel and with the controls by themselves (not that that should matter). For my testing I took the listsearch page from the new sample website and just added a label to it. Then in the selectedindexchanged event of the ddl I set the label text to the current datetime just to test the postback funtionality I want to use. As far as I know I have left the ddl and the extender alone with the exception of setting the autopostback.


Hmmm. So is there a way then to cancel the binding of the controls contents on the postback? I'm guessing check the Page.IsPostBack and Page.IsCallBack properties, but where would I do that?

Thanks,

BTW. Below are the pieces of code I am working with.

<script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); ListBox1.DataSource = GetWordListText(); ListBox1.DataBind(); DropDownList1.DataSource = GetWordListText(); DropDownList1.DataBind(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToLongTimeString(); }</script><asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" Width="100px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True" /><asp:Label ID="Label1" runat="server" Text="Label" Width="125px"></asp:Label><ajaxToolkit:ListSearchExtender ID="ListSearchExtender2" runat="server" TargetControlID="DropDownList1" PromptCssClass="ListSearchExtenderPrompt"> </ajaxToolkit:ListSearchExtender> </ContentTemplate></asp:UpdatePanel>

If you do do something like this it should work:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if(!IsPostBack ) {
ListBox1.DataSource = GetWordListText();
ListBox1.DataBind();
DropDownList1.DataSource = GetWordListText();
DropDownList1.DataBind();

}
}


Thanks Damian, that did it. Also, thanks so much for you work with the toolkit.

ListSearch

What release is list search part of?

never mind I found it

listsearch

I have put a list box search extender control on my page. It works great except for two things. First if I click in the list box it activates the index change and that may not be data field I wanted. Two when using the search option and I found the record I wanted. The record was highlighted and when I clicked on it nothing happens. I can click on other fields and the list box works great. I need some help.

when i select an item by the listseach the selecteditemchanged event doesn't works


Ajax ListSearchExtender does not force its targeted DropDownList to postback once the desired item has been selected.

You need to write a javascript to force the DropDownList to postback once it loses its focus.

I had the same problem and here's how I got around to it.

ASP

<asp:DropDownList ID="ddl_LocationID" runat="server" AutoPostBack="True" Width="200"

OnSelectedIndexChanged="ddl_LocationID_SelectedIndexChanged"

OnLoad="ddl_LocationID_Load"></asp:DropDownList>

Code Behind

protected void ddl_LocationID_Load(object sender, EventArgs e)
{
string script = ClientScript.GetPostBackEventReference(ddl_LocationID, "");
ddl_LocationID.Attributes.Add("onblur", script);
}

protected void ddl_LocationID_SelectedIndexChanged(object sender, EventArgs e)
{
// Do something when an item has been selected
}


Lonnie, try this:

HTML

<script type="text/javascript">function UpdateLabel(){var btn = $get("ctl00_MainContent_btnTest");if(btn != null) { btn.click(); }}</script><asp:UpdatePanel ID="ListBox_UpdatePanel" UpdateMode="Conditional" runat="server"><ContentTemplate><asp:ListBox ID="ListBox1" onclick="UpdateLabel();" runat="server"><asp:ListItem Text="Item 1" Value="1" Selected="true" /><asp:ListItem Text="Item 2" Value="2" /><asp:ListItem Text="Item 3" Value="3" /><asp:ListItem Text="Item 4" Value="4" /><asp:ListItem Text="Item 5" Value="5" /></asp:ListBox><asp:Label ID="lblItem" runat="server" /><asp:Button ID="btnTest" Text="Update Label" OnClick="UpdateLabel" runat="server" /><ajaxToolkit:ListSearchExtender ID="lseListBox1" TargetControlID="ListBox1" runat="server" /></ContentTemplate></asp:UpdatePanel>

Code Behind:

Protected Sub UpdateLabel(ByVal senderAs Object,ByVal eAs EventArgs)Me.lblItem.Text =Me.ListBox1.SelectedValueEnd Sub

fikreter, you need to put AutoPostBack="true" on your listbox:

Let me know if any of you need further help ...


The latest toolkit release containts an updated version of the ListSearch Extender which will fire an OnChange (and therefore postbacks) when the target List loses focus (if you Tab or click away), or if you hit Enter.

Regards,

Damian

ListSearch with ~15,000 items under dropdownlist

I have a dropdownlist with around 15,000 items, which can be quite irritating for a user to select the right item.

So, I put in ListSearch to facilitate the selection process, but now I'm noticing that there's about 5 second delay from the moment I start typing the first few characters of the item and the time I actually see the typed characters below my dropdownlist. And 5 seconds is way too long of a delay!!

When I tried the same ListSearch on a dropdownlist with a fewer number of items (say...about 100), then it worked instantaneously.

Has anyone seen similar problem? And how can I make ListSearch work faster?


Thanks.


Hi,

The ListSearch delays any processing until the first time the user starts typing. This is by design (on a number of our components) because if you put a few dozen components in a repeater you don't want them to all do their processing at once when the page loads. I'm a little skeptical that you really want to put 15,000 items in a drop down (instead of providing a search/results selection UI with something like modal popup), but you could probably tweak the ListSearch beahvior pretty easily to start processing the items in its initialize function.

Thanks,
Ted


I agree with you. Putting more than 15,000 items under a dropdownlist is an overkill, but I'm currently migrating our old ACCESS application to ASP 2.0 and it is required to stay with the same dropdown control. Apparently, ACCESS's version of dropdownlist can handle 15,000 items and has the capability of search incrementally. So, I'm kinda stuck with a dropdownlist here. :-(

I guess the users don't want to go through few more clicks with the search/results selection page.


With that aside, what did you mean by "tweaking ListSearch"?? Would you be able to show me an example or direct me to some website where I can look into?

Thanks for your help.

-Brian


Hi,

Get the full source version of the Toolkit and look at the AjaxControlToolkit\ListSearch\ListSearchBehavior.js file. You can experiment with moving the _isSorted check (line 242) from _onKeyDown to initialize (remember to rebuild when you change one of the scripts as they're embedded resources). I think this would help fix the delay you're seeing the first time a user accesses the list.

Thanks,
Ted


Thank You!


I've written a blog post explaining how you can alter the ListSearch Extender to speed up the initialization by giving it a hint as to whether the target list is sorted or not. It is the determination of whether thie list is sorted or not that takes a long time.

http://damianblog.com/2007/06/19/speeding-up-listsearchextender/

If there is enough interest, I'd be happy to add the changes to the control toolkit.


Thank you for this. I will definitely take a look at this and hopefully I'll get the ListSearch Extender to work faster.

-Brian

ListSearch Tab or enter key event?

Hello,

I'm pretty new to Ajax and Aps.net so hopefully this question can easily be answered.

I have a ListSearch that extends a dropdownlist. When a user types for the list search, the correct item is chosen but I also want the dropdownlist to fire an event, preferably SelectedIndexChanged, if the user clicks the key Tab or enter. Right now a tab shows the correct item when a Tab is clicked but no event is fired. The SelectedIndexChanged event fires when a user clicks changes a GridView. I want the grid view to also change when the tab or enter key is pressed when using the ListSearch Any Ideas?

thanks for the help.

We have anissue tracking the selectedindex change event. If the tab key is hit when the focus is in the listbox should cause the onblur event to fire and you can hook into that. See thisbug for the enter/tab autopostback issue. You could update it with your scenario as well to make sure that the fix is covers it.

I'm running into the same problem as you guys are. I love how ListSearch Ajax works, but can't use it because it doesn't fire an event for the dropdownlist or manage the tab index.

In the meantime, I found this add-on tool that does what I'm looking for. Of course, it comes with a price. :-(

Go check out the "Contact Information" section.

http://samples.asplib.net/AspLibSamples/ComboBox.aspx

ListSearch doesnt work with Dropdownlist AutoPostBack

ListSearch works fine finding a specific item on a dropdownlist, but doesn't fire an AutoPostBack event when I tab over (or tab out).

I found this 3rd party add-on control that does exactly what I'm looking for, but was wondering if there's a similar dropdownlist available from Microsoft.


Check out the "Contact Information" section.

http://samples.asplib.net/AspLibSamples/ComboBox.aspx


Also, any easy way to display the prompt text "left" of the dropdownlist. Apparently, there are only two options: top or bottom.

Thanks.


Hi,

You can use the following code to force a postback when the dropdownlist losts focus.


string script = ClientScript.GetPostBackEventReference(DropDownList1, "");
DropDownList1.Attributes.Add("onblur", script);

Hope this helps.


That did the trick! Thanks!!

ListSearch doesn´t work with CascadingDropDown

ListSearch is a wonderful control I love it, but I am a little disappointed because it doesn't work in conjunction with CascadingDropDown, ListSearch found the entry in the DropDownList but when you choose the item CascadingDropDown doesn't trigger the event.

Hello there,

This is a known issue that I'm planning on fixing for the next release. Could you vote for this here:http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=8771

Thanks,

Damian


Thanks for your response, I have already vote done. I will be been appreciated if you warn me when this be done.