Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
webforms : use infragistics webdropdown in updatepanel
posted

My goal is to having a infragistics dropdownlist enabling multi selection and at each selection I want an event fired server side without refreshing the whole page.

This is my aspx page :

<%@ Register assembly="Infragistics45.Web.v16.1, Version=16.1.20161.1000, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.ListControls" tagprefix="ig" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<ig:WebDropDown ID="WebDropDown1" runat="server" Width="200px" OnSelectionChanged="WebDropDown1_SelectionChanged" EnableMultipleSelection="true" EnableClosingDropDownOnSelect="false" AutoPostBack="true">
</ig:WebDropDown>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlId="WebDropDown1" EventName="SelectionChanged"/>
</Triggers>
</asp:UpdatePanel>
</asp:Content>

This is my code-behind page :

private List<string> allPossiblechoices = new List<string>() { "a", "b", "c","d","e" };

private List<string> defaultChoices = new List<string>() { "a", "b", "c" };

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
foreach(var choice in allPossiblechoices)
{
WebDropDown1.Items.Add(
new DropDownItem()
{
Text = choice,
Value = choice,
Selected = defaultChoices.Contains(choice)
}
);
}
}
}

protected void WebDropDown1_SelectionChanged(object sender, DropDownSelectionChangedEventArgs e)
{
// I put a breakpoint here to see what e.NewSelection and e.OldSelection are
}

By default, when the page is requested for the first time, the dropdown is composed of a,b,c,d,e and only a,b,c are selected.

When I select d, a request is indeed send to the server (I put a breakpoint in my event handler) and the results are correct :

EventArgs e.OldSelection contains a,b,c.<br>
EventArgs e.NewSelection contains a,b,c,d.

Then, I deselect d and the results are the following :

EventArgs e.OldSelection contains a,b,c.d.<br>
EventArgs e.NewSelection contains a,b,c,d.

I don't understand why EventArgs e.NewSelection contains d even if I deselected it.

The fact that it's even more strange, is that I have done the same thing without the updatePanel and everything works fine, the selection (new and old) are correct.

Thanks in advance for your help.

  • 18204
    Offline posted

    Hello bssy,

    Thank you for posting in our forums!

    You are setting the AutoPostBack property to true, but you are not setting the individual AutoPostBackFlags.

    If you set the AutoPostBackFlags to "Async" like in the below code snippet, you should have your desired results.

    <ig:WebDropDown ID="WebDropDown1" runat="server" Width="200px"
        OnSelectionChanged="WebDropDown1_SelectionChanged" EnableMultipleSelection="true"
        EnableClosingDropDownOnSelect="false" AutoPostBack="true">
        <AutoPostBackFlags SelectionChanged="Async" ValueChanged="Async" />
    </ig:WebDropDown>

    If you need further assistance with this, please let me know.