This is a migrated thread and some comments may be shown as answers.

ajax stops working after deleting the last item from listbox

1 Answer 51 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
ido nahmias
Top achievements
Rank 1
ido nahmias asked on 29 May 2014, 02:38 PM
Hello,

Ajax stops working after deleting the last item from Listbox

I have listbox, panel and 2 buttons- the first button deletes items from the listbox using java script (1) and the second button is  used to send ajax requests in order to hide and show the panel (2).

While deleting the items from the listbox, the ajax buttons works and hides/shows the panel but after deleting the last item from the listbox, the ajax stops working.

There is no error in the client side and neither on server side- I add break points at the server side in the Page_Load, I notice the function wasn't even called.


(1)-listBox.deleteItem(selectedItem);
(2)- panel.visible=false/true

Thanks,





1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 May 2014, 06:43 AM
Hi ido nahmias,

Please have a look into the sample code snippet which works fine at my end. Please provide your code if it doesn't help.

ASPX:
<telerik:RadListBox ID="RadListBox1" runat="server">
    <Items>
        <telerik:RadListBoxItem Text="Item1" />
        <telerik:RadListBoxItem Text="Item2" />
        <telerik:RadListBoxItem Text="Item3" />
    </Items>
</telerik:RadListBox>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
    <telerik:RadTextBox ID="RadTextBox1" runat="server" Text="Test">
    </telerik:RadTextBox>
</telerik:RadAjaxPanel>
<telerik:RadButton ID="RadButton1" runat="server" Text="DeleteItem" AutoPostBack="false"
    OnClientClicked="DeleteSelectedItem">
</telerik:RadButton>
<telerik:RadButton ID="RadButton2" runat="server" Text="Change Visibility" OnClick="RadButton2_Click">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function DeleteSelectedItem(sender, args) {
        var listbox = $find("<%=RadListBox1.ClientID %>");
        listbox.trackChanges();
        listbox.get_items().removeAt(listbox.get_selectedIndex());
        listbox.commitChanges();
        var button = $find("<%=RadButton2.ClientID%>");
        button.click();
    }
</script>

C#:
protected void RadButton2_Click(object sender, EventArgs e)
{
    if (RadAjaxPanel1.Visible==true)
        RadAjaxPanel1.Visible = false;
    else
        RadAjaxPanel1.Visible = true;
}

Thanks,
Shinu.
Tags
ListBox
Asked by
ido nahmias
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or