Monday, March 26, 2012

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

No comments:

Post a Comment