clearSelection() not surviving postback

2 posts, 0 answers
  1. Andrew Dixon
    Andrew Dixon avatar
    15 posts
    Member since:
    Apr 2010

    Posted 29 Aug 2011 Link to this post


    I have a RadListbox (single select mode) and a button which deselects all items in the RadListbox using clearSelection() in javascript.  This appears to work, until there is a postback at which point the item is selected again.

    Here is some example code which exhibits this problem (p_Postback_Click is just an empty event handler to cause a postback):

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestClearSelection.aspx.cs" Inherits="TestClearSelection" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <form id="form1" runat="server">
        <script type="text/javascript">
            function ClearListbox() {
                lb = $find("RadListBox1");
        <ajax:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></ajax:ScriptManager>
            <telerik:RadListBox ID="RadListBox1" runat="server">
                    <telerik:RadListBoxItem Text="Item 1" />
                    <telerik:RadListBoxItem Text="Item 2" />
                    <telerik:RadListBoxItem Text="Item 3" />
            <asp:Button ID="b_ClearSelection" runat="server" Text="Clear Selection" onclientclick="ClearListbox(); return false;" />
            <asp:Button ID="b_PostBack" runat="server" Text="Postback"
                onclick="b_PostBack_Click" />
    Is this a bug, or am I just missing something else that I need to do?  I've seen trackChanges and commitChanges in the documentation but these seem to be needed only when adding or deleting ListItems clientside.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Sep 2011 Link to this post

    Hello Andrew,

    Try the following JavaScript to persist clear selection on postback.
    <script type="text/javascript">
    function ClearListbox()
     lb = $find("RadListBox1");

Back to Top