Proper way to Enable/Disable RadListBox from both client and server side?

11 posts, 0 answers
  1. Nicholas Walker
    Nicholas Walker avatar
    55 posts
    Member since:
    May 2006

    Posted 04 Nov 2009 Link to this post

    Working with version 2009.2.826.20.

    I have a RadListBox on a page that I need to enable/disable via javascript.  When the page loads, the control defaults to Enabled="False", which seems to work fine.  However, in the javascript, there doesn't appear to be a way to enable the control itself directly.  The enable/disable functions are on the items only.

    So I tried disabling all the items in the RadListBox at load, leaving the control itself enabled.  But when the items are disabled, I can't seem to get the client script to enable them (I can get it to work the other way though for some odd reason - disabling items from an enabled state works OK).

    This has been a maddening problem today!  Seems like there should a simple enable/disable functionality on both the server and the client RadListBox object.  Can someone there please provide a working example of how this works?

    Thanks,
    --nick
  2. Nicholas Walker
    Nicholas Walker avatar
    55 posts
    Member since:
    May 2006

    Posted 04 Nov 2009 Link to this post

    Sorry, don't think I was clear in my post - frustration clouding my mind.  Ultimate goal:

    I need to start with a RadListBox that gets disabled in the code behind in Page_Load.  I then need to enable/disable that listbox from javascript based on a radio button the end user selects.  When the page posts back, I then need to determine the state of the listbox and what items are selected.

    Thanks,
    --nick
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 10 Nov 2009 Link to this post

    Hello Nicholas Walker,

    You are right about everything - the listbox is missing the enable()/disable() methods and also enabling all items on the client does not enable the whole listbox.
    Here is a workaround:

    <telerik:RadListBox ID="RadListBox1" runat="server" Skin="Forest">
        <Items>
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem1" />
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem2" />
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem3" />
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem4" />
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem5" />
        </Items>
    </telerik:RadListBox>
     
    <asp:RadioButtonList ID="RadioButtonList1" runat="server" onclick="onRadioClick(this);">
        <asp:ListItem>Disable</asp:ListItem>
        <asp:ListItem>Enable</asp:ListItem>
    </asp:RadioButtonList>
     
    <script type="text/javascript">
        function onRadioClick(radio) {
            var checkedValue = $telerik.$("input[name='RadioButtonList1']:checked").val();
            var list = $find("<%= RadListBox1.ClientID %>");
            if (checkedValue == "Enable") {
                list.get_element().disabled = "";
                var items = list.get_items();
                for (var i = 0; i < items.get_count(); i++) {
                    var item = items.getItem(i);
                    item.enable();
                    item.get_element().disabled = "";
                }
            }
            else {
                list.get_element().disabled = -1;
            }
        }
    </script>

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            foreach (RadListBoxItem item in RadListBox1.Items)
            {
                item.Enabled = false;
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write(RadListBox1.SelectedItem.Text);
    }

    We will do our best to fix the problem as soon as possible and include it in the latest internal builds and SP1.

    All the best,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. James Edgell
    James Edgell avatar
    4 posts
    Member since:
    Sep 2009

    Posted 06 Apr 2010 Link to this post

    This solution does not appear to work if the ListBox is disabled on the server side and enabled on the client side. Yes, the list does get enabled, but non of the checked vales are sent back to the server when posted.

    P.S. I am using CheckBoxes="True"  in my list.
  6. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 07 Apr 2010 Link to this post

    Hello James Edgell,

    We have fixed this issue since Q1 2010. You can download the latest version and upgrade to resolve the issue.

    Kind regards,
    Simon
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. James Edgell
    James Edgell avatar
    4 posts
    Member since:
    Sep 2009

    Posted 07 Apr 2010 Link to this post

    I'm using RadControls_for_ASP.NET_AJAX_2010_1_309_dev and I still have the problem. Please note that I'm using Checkboxes.
  8. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 12 Apr 2010 Link to this post

    Hello James Edgell,

    It seems that this is a different bug than what we have originally thought. We will try to get it fixed for the next week's internal build. Meanwhile you could use the following workaround:

    1) Don't disable the listbox on the server.
    2) Do it in the client pageLoad event.
    3) Add a hidden field to store the RadListBox' disabled state.

    I have prepared sample project that demonstrates the approach. You can find it as an attachment.

    Sincerely yours,
    Genady Sergeev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Margaret
    Margaret avatar
    1 posts
    Member since:
    Dec 2010

    Posted 16 Sep 2011 Link to this post

    Hi,

    What is the status of this issue?  I am running File version 2011.2.712.40 of Telerik.Web.UI.dll and the problem still does not seem to be resolved.

    Thank you.
    Margaret
  10. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 21 Sep 2011 Link to this post

    Hi Margaret,

    The problem is fixed in our latest release - Q2.2011 Service Pack 1. Please try it on your side.

    Regards,
    Peter Filipov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  11. Cary
    Cary avatar
    1 posts
    Member since:
    Apr 2011

    Posted 23 Dec 2011 Link to this post

    I cannot get the enable and disable to work correctly for the RadListItems on the client side.  I was wondering if you could send a code example of how to properly use those two on the RadListItems.  Thanks.
  12. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 26 Dec 2011 Link to this post

    Hello,

    You can read how to manipulate the ListBoxItem's client object here.

    As an example, here is a sample code that disables the first item of the ListBox:

    var listbox = $find("<%= RadListBox1.ClientID %>");
    var item = listbox.get_items().getItem(0);
    item.disable();
    //or
    //item.set_enabled(false);

     

    Greetings,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017