Reputation:
I'm trying to add items to a asp:BulletedList in javascript. But after the postback the added items aren't in BulletedList.Items.
Is there a trick to being able to add items to the BulletedList on the client side?
Upvotes: 0
Views: 810
Reputation: 62260
Unfortunately, you cannot alter ListItem at clientside, because it is a server control.
Easiest way will be to add new ListItem using Ajax such as UpdatePanel.
For example,
<asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
<asp:TextBox runat="server" ID="TextBox1" />
<asp:Button runat="server" ID="Button1" Text="Add" OnClick="Button1_Click" />
<br />
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:BulletedList ID="BulletedList1" runat="server">
<asp:ListItem Text="One" />
<asp:ListItem Text="Two" />
</asp:BulletedList>
</ContentTemplate>
</asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
BulletedList1.Items.Add(new ListItem(TextBox1.Text));
}
Upvotes: 1