Reputation: 2256
I am using the dropdown-check-list plug-in to create a dropdownlist that allows multiple selection.
However, it is getting duplicated in every postback after it has been used, which produces something like this:
Does anyone know why this is happening and how to fix it?
UPDATE: About the request to show some code:
Javascript:
$(document).ready(function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(load_lazyload);
load_lazyload();
...
}
function load_lazyload() {
$("#ContentPlaceHolder1_userControl1_listBoxMultiValueNumbers").dropdownchecklist();
...
}
C#: this is how the listBox is being populated:
listBoxMultiValueNumbers.DataTextField = ds.Tables[0].Columns["number"].Caption;
listBoxMultiValueNumbers.DataValueField = ds.Tables[0].Columns["number"].Caption;
listBoxMultiValueNumbers.DataSource = ds;
listBoxMultiValueNumbers.DataBind();
listBoxMultiValueNumbers.Items.Insert(0, new ListItem("Select numbers", "-1"));
UpdatePanelUCCNFT.Update();
Upvotes: 0
Views: 1654
Reputation: 2689
You're calling the load function twice, thus getting two drop downs. Once registered with ...add_endRequest(load_lazyload)
and again explicitly. I'd guess if you remove the call to add_endRequest
it would fix it (after all, you already have it wrapped in $(document).ready()
)
Upvotes: 0
Reputation: 385
I don't if you still have the problem or not. I just encountered similar problem where I had, dropdownlist gets duplicating after every postback. This solved my problem
fillDropDownList()
{
String selectValue = DropDownList.SelectedValue();
DropDownList.Items.Clear(); // to clear the duplicates
DropDownList.SelectedValue = selectValue; // to restore previously selected value
DropDownList.Items.Insert("0", New ListItem(" Select ", ""));
DropDownList.DataBind();
}
in the page_load
if (Page.IsPostBack)
{
fillDropDownList();
}
I hope this helps!
Upvotes: 0
Reputation: 707
i think you have load your dropdown on page load without using postback event..that's why its binding everytime..
use page_load()
{
if(!ispostback)
{
//load your dropdown here
}
}
Upvotes: 1