Combobox with EnabledLoadOnDemand

9 posts, 1 answers
  1. Grigory
    Grigory avatar
    12 posts
    Member since:
    Nov 2011

    Posted 30 May 2012 Link to this post

    Hello!  If it's possible to disable user input in radcombobox with enabled load on demand set to true?  

    I have a problem with user input in radcombobox, user could type everything in radcombobox and after submit when I'm trying to convert SelectedValue to integer there is an exception.  If it possible to select items or type only non-custom text?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 May 2012 Link to this post

    Hi Grigory,

    Try the following JavaScript to disable user input in RadComboBox.

    JS:
    <script type="text/javascript">
      function pageLoad()
        {
            var combo =  $find("<%= RadComboBox1.ClientID%>");
            var input = combo.get_inputDomElement();
            input.disabled = "disabled";
        }
    </script>

    Hope this helps.

    Regards,
    Princy.
  3. Grigory
    Grigory avatar
    12 posts
    Member since:
    Nov 2011

    Posted 30 May 2012 Link to this post

    Thanks a lot , Princy
  4. Grigory
    Grigory avatar
    12 posts
    Member since:
    Nov 2011

    Posted 30 May 2012 Link to this post

    But if it possible to prevent text typing which don't exist in Item list?
  5. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 01 Jun 2012 Link to this post

    Hi Grigory,

    If you have load-on-demand enabled for RadComboBox in your scenario, there is no need to add a functionality that will prevent the typing in the input area if it does not match any item from the ItemsCollection of the control. When the user starts typing, no items will be fetched from the data source if there are no matches.
    Take a look at the following online demo for more information on load-on-demand:
    http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx.

    Regards,
    Ivana
    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.
  6. Grigory
    Grigory avatar
    12 posts
    Member since:
    Nov 2011

    Posted 01 Jun 2012 Link to this post

    http://screencast.com/t/efCwZi4PXfC6

    Can you see the screenshot? 

    Yes there are empty list while I'am typing something wrong to the combobox input, but if I click outside the combobox the incorrect value will be selected. In my scenario on postback there are selected value parse to integer  and if there are no value which I typed there will be exception .. 
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Jun 2012 Link to this post

    Hi Grigory,

    As far as I know it is not possible to disable typing according to the RadComboBoxItem. One suggestion is that you can check in the SelectedIndexChanged event as follows.

    C#:
    protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            int i=0;
            foreach (RadComboBoxItem item in RadComboBox1.Items)
            {
                if (item.Text == RadComboBox1.Text)
                {
                    i = 1;
                }
            }
            if (i == 0) //Typed text is not RadComboBoxItem
            {
                RadComboBox1.Text = "";
                //Your code
            }
            else  //Typed text is a RadComboBoxItem
            {
                //Your code
            }
        }

    Hope this helps.

    Thanks,
    Shinu.
  8. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 06 Jun 2012 Link to this post

    Hi Grigory,

    If you are using server-side loading of items, you could an 'if'  check to your code which will make sure that the number of items being loaded is not zero; if it is zero, however, you should clear the text of the RadComboBox like this:
    RadComboBox1.Text = "";

    If you, on the other hand, are loading items from a Web server you could take advantage of the OnClientItemsRequested event where you could check the number of items being loaded from the service. Just like in the previous case, If this number is zero then you set the text of RadComboBox to empty string.

    I hope this will help.

    Greetings,
    Ivana
    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.
  9. Grigory
    Grigory avatar
    12 posts
    Member since:
    Nov 2011

    Posted 06 Jun 2012 Link to this post

    Thanks a lot to both of you!
Back to Top