so my problem is fairly simple i have 2 list-boxes and one button.
when an item is selected in listbox2 and the button is clicked i would like to add the selected item to listbox1.
And it all seams to work until I add the second item. then listbox1 doesn’t refresh it’s items…
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
<asp:ListBox ID="ListBox2" runat="server"></asp:ListBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListBox2.Items.Add(new ListItem("1", "1"));
ListBox2.Items.Add(new ListItem("2", "2"));
ListBox2.Items.Add(new ListItem("3", "3"));
ListBox2.Items.Add(new ListItem("4", "4"));
ListBox2.Items.Add(new ListItem("5", "5"));
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ListBox2.SelectedIndex != -1)
{
ListBox1.Items.Add(ListBox2.SelectedItem);
}
}
}
You can add
UpdateMode=conditionalto yourUpdatePanelAnd set
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />