Radcombobox enabled/disabled onload via javascript

15 posts, 0 answers
  1. Tony Polad
    Tony Polad avatar
    19 posts
    Member since:
    Apr 2009

    Posted 14 Aug 2008 Link to this post

    Hi,

    I really need to enabled/disabled the RadComboBox via Javascript when the page is load. I need to do it so I can enable / disable the combobox again when the user click another button via JavaScript. I dont want to postback.

    I have put the following code in the Page_Init()

    ClientScript.RegisterStartupScript(Page.GetType(),

    "mykey", "ToggleRadcomboBox();", true);

    The javascript is as follow
    function ToggleRadcomboBox()
    {
        var combo = $find("<%= RadComboBox1.ClientID %>");
        //the combo return null
        combo.set_enabled(false);
        return false;
    }

    The above code will return me with "null value",
    but, when I used:
    function ToggleRadcomboBox()
    {
        var combo = document.getElementByID("<%= RadComboBox1.ClientID %>");
        // found combo, but unable to do anything
        // combo.set_enabled(false) does not work when using document.getElementByID
        combo.disabled = true;
        return false;
    }

    Could you please help me out ?

    Thanks.
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 14 Aug 2008 Link to this post

    Hello Susanto Siman,

    The combobox is null because it is not yet initialized.
    You can enable/disable the combobox in the pageLoad() event which is fired when all controls on the page are initialized.

    I hope this helps.

    Regards,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tony Polad
    Tony Polad avatar
    19 posts
    Member since:
    Apr 2009

    Posted 14 Aug 2008 Link to this post

    Hi,

    I did tried to put it on page_load() as well.

    None works.

    I did tried pageload on javascript as well and it still not working.

    Any idea ?

    It would be great if you provide me with a very simple sample.

    Thanks.
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Aug 2008 Link to this post

    Hi Susanto Siman,

    It is too early to find the combobox and set its properties using javascript.

    So, what you need to do is just put this code in your aspx page and the combo will be disabled on every page load:

    <script type="text/javascript"
    function pageLoad() 
        var combo = $find("<%= RadComboBox1.ClientID %>"); 
        combo.disable(); 
    </script>  


    Sincerely yours,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Chintan
    Chintan avatar
    1 posts
    Member since:
    Jul 2011

    Posted 30 Jul 2011 Link to this post

    I am trying to get disabled combo box through java script  , its not properly enabled my combo. its not showing dropdwon list while we enabled this control, Below my code
    function checkCheckBox() {
        var chk = document.getElementById("ctl00_cph_Main_chkOther");
        if (chk.checked == true) {
            var agree = confirm("Are you sure that you want change the default selection criteria?");
            var TermCode = document.getElementById("ctl00_cph_Main_rcmbTermCode");
            //alert(agree+'   HI');
            if (agree == false) {
                document.getElementById("ctl00_cph_Main_chkOther").checked == false;
                document.getElementById("ctl00_cph_Main_rcmbTermCode").disabled = true;
                return false;
            }
            else {
               document.getElementById("ctl00_cph_Main_rcmbTermCode").disabled = false;
                return true;
            }
        }
        else {
            document.getElementById("ctl00_cph_Main_rcmbTermCode").disabled = true;
        }
    }

    Please resolve my problem .

  7. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 31 Jul 2011 Link to this post

    Hi Chintan,

    Please try this JavaScript code to enable / disable the RadComboBox.

    var combo = $find("<%= rcmbTermCode.ClientID %>");
    combo.enable(); // to enable the RadComboBox
    combo.disable(); // to disable the RadComboBox

    You may want to take a look at this page to get more information on how to manipulate the RadComboBox on the client side.
    http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html

    Hope that helps!
    Thad
  8. Jagz W
    Jagz W avatar
    17 posts
    Member since:
    Mar 2012

    Posted 24 Mar 2012 Link to this post

    Thanks fhis sovled the problem.

    Early i was trying like this: $find('<%= rdcomboEduWork.ClientID %>').disable();
  9. Sravanthi
    Sravanthi avatar
    21 posts
    Member since:
    May 2012

    Posted 20 Aug 2012 Link to this post

    combobox.disable() it is erroring out, saying disable() is not a valid function.
    ALso, i am doing this onload()

    Thanks,
    Sri
  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Aug 2012 Link to this post

    Hi,

    Unfortunately I cannot replicate the issue at my end. Here is the full code that I tried which worked as expected.
    aspx:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Height="300px"  OnClientLoad="OnClientLoad">
      <Items>
        <telerik:RadComboBoxItem Text="Fairy Tales" />
        <telerik:RadComboBoxItem Text="Fiction" />
        <telerik:RadComboBoxItem Text="Adventure" />
      </Items>
    </telerik:RadComboBox>
    JS:
    function OnClientLoad(sender, args) {
     $find('<%= RadComboBox1.ClientID %>').disable();
           //or
      sender.disable();
    }

    Thanks,
    Princy.
  11. Sravanthi
    Sravanthi avatar
    21 posts
    Member since:
    May 2012

    Posted 21 Aug 2012 Link to this post

    This is the combobox declaration in aspx ::
    <telerik:RadComboBox ID="cmbbranch" runat="server"/>

    and the javascript is inside C# code as follows ::

     stringabc.Append("var cmb = document.getElementById(\"" + cmbbranch.ClientID + " \"); if(document.getElementById(\""
                    + ddlmethodtype.ClientID + "\").value == \"Customer Pickup\") { cmb.enable() }  else { cmb.disable(); };");

    I tried both $find and document.getelementbyid for ::
    var cmb = document.getElementById(\"" + cmbbranch.ClientID + " \");

    it says either cmb is null or disable() is not a valid function.

    Thanks for the help. Aprreciate it.
    Sri!!

  12. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Aug 2012 Link to this post

    Hi,

    Try disabling the combobox as shown below.
    C#:
    string script = "function f(){$find(\"" + RadComboBox1.ClientID + "\").disable(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
    ScriptManager.RegisterStartupScript(Page, Page.GetType(),
    "key", script, true);

    Thanks,
    Princy.
  13. Sumit
    Sumit avatar
    2 posts
    Member since:
    Jan 2012

    Posted 26 Feb 2013 Link to this post

    Hi,
    $find(
    '<%= RadComboBox1.ClientID %>').disable();
    is not working while RadGrid is in edit mode.

    Can use as follows: 

       function OnClientSelectedIndexChanged(sender, eventArgs)
            {
                var clientId = sender.get_id();
                var ddlvalue = document.getElementById(clientId);
                ddlvalue.setAttribute('readOnly', 'readOnly'); // to enable
                ddlvalue.setAttribute('readOnly', ''); // to disable

           }

    All the best.

  14. Zaher
    Zaher avatar
    5 posts
    Member since:
    Jan 2012

    Posted 14 Oct 2013 Link to this post

    @ Tony Polad
    please try
     
     $(document).ready(function(){
               ToggleRadcomboBox()
            });

    function ToggleRadcomboBox()
    {
        var combo = $find("<%= RadComboBox1.ClientID %>");
        //the combo return null
        combo.set_enabled(false);
        return false;
    }
  15. Ramkumar
    Ramkumar avatar
    12 posts
    Member since:
    Nov 2013

    Posted 05 Dec 2013 Link to this post

    hi,
     I need radcombobox item to disable except the item which I checked. I am havin no of item in radcombobox. if I check any one item rest all items to be disabled. Can you please help me?
  16. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Dec 2013 Link to this post

    Hi Ramkumar,

    Please have a look into the following JavaScript to achieve your scenario.

    JavaScript:
    <script type="text/javascript">
        function OnClientItemChecked1(sender, args) {
            var count = sender.get_items().get_count();
            if (args.get_item().get_checked() == true) {
                for (var i = 0; i < count; i++) {
                    if (sender.get_items().getItem(i).get_checked() == false) {
                        sender.get_items().getItem(i).set_enabled(false);
                    }
                }
            }
            else {
                for (var i = 0; i < count; i++) {
                    sender.get_items().getItem(i).set_enabled(true);
                }
            }
        }
    </script>

    Thanks,
    Princy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017