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

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

10 Answers 591 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Nicholas Walker
Top achievements
Rank 1
Nicholas Walker asked on 04 Nov 2009, 10:28 PM
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

10 Answers, 1 is accepted

Sort by
0
Nicholas Walker
Top achievements
Rank 1
answered on 04 Nov 2009, 10:48 PM
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
0
Veselin Vasilev
Telerik team
answered on 10 Nov 2009, 12:41 PM
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.
0
James Edgell
Top achievements
Rank 1
answered on 06 Apr 2010, 11:10 PM
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.
0
Simon
Telerik team
answered on 07 Apr 2010, 12:52 PM
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.
0
James Edgell
Top achievements
Rank 1
answered on 07 Apr 2010, 04:37 PM
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.
0
Genady Sergeev
Telerik team
answered on 12 Apr 2010, 04:30 PM
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.
0
Margaret
Top achievements
Rank 1
answered on 16 Sep 2011, 06:58 PM
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
0
Peter Filipov
Telerik team
answered on 21 Sep 2011, 08:24 AM
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
0
Cary
Top achievements
Rank 1
answered on 23 Dec 2011, 11:00 PM
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.
0
Bozhidar
Telerik team
answered on 26 Dec 2011, 05:46 PM
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
Tags
ListBox
Asked by
Nicholas Walker
Top achievements
Rank 1
Answers by
Nicholas Walker
Top achievements
Rank 1
Veselin Vasilev
Telerik team
James Edgell
Top achievements
Rank 1
Simon
Telerik team
Genady Sergeev
Telerik team
Margaret
Top achievements
Rank 1
Peter Filipov
Telerik team
Cary
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or