is there a click dropdown event?

5 posts, 1 answers
  1. John Hadjioannou
    John Hadjioannou avatar
    30 posts
    Member since:
    Dec 2005

    Posted 12 Aug 2010 Link to this post

    I would like to clear the text of the combobox when the user presses the button to open the dropdown, but not when it opens of its own accord.  Is there a click event for the button that I can use, or some other way of achieving this?

    John
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Aug 2010 Link to this post

    Hello John,

    I guess you want to open the RadComboBox and clear its text in an external button click. If so try the following code snippet.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox2" runat="server" Text="select" AllowCustomText="true">
        <Items>
           <telerik:RadComboBoxItem Text="aaa" />
           <telerik:RadComboBoxItem Text="bbb" />
        </Items>
     </telerik:RadComboBox>
            
     <asp:Button ID="Button4" runat="server" Text="Open" OnClientClick="return clearText();"  />

    Java Script:
    <script type="text/javascript">
       function clearText() {
          var combo = $find("<%=RadComboBox2.ClientID %>");
          combo.clearSelection();
          combo.showDropDown(true);
          return false;
        }
    </script>

    Thanks,
    Princy.
  3. John Hadjioannou
    John Hadjioannou avatar
    30 posts
    Member since:
    Dec 2005

    Posted 17 Aug 2010 Link to this post

    Hi Princy

    Thank you for the suggestion.

    My situation is a little different.

    I would like the text to clear when the user clicks on the button that is part of the combobox to open the dropdown.

    The rationale is this:  If an item is already selected the only item that will show in the dropdown initially is the selected item, meaning that the user will have to clear the text manually to see the other choices.  If the user is opening the dropdown it is because they want to change the selected item - clearing the text for them saves them a step.

    I suppose what I am looking for is a weay of finding the Id of the combobox's button so I can attach an on-click event to it.

    Any ideas?

    Thanks
    John
  4. Answer
    Simon
    Admin
    Simon avatar
    2281 posts

    Posted 18 Aug 2010 Link to this post

    Hi John Hadjioannou,

    You can handle the DropDownOpening event and verify whether the event has been risen by the Image Button of the RadComboBox and then clear the text or execute some other logic, e.g.
    function onDropDownOpening(sender, eventArgs) {
        if (eventArgs.get_domEvent().target == sender.get_imageDomElement())
            sender.set_text("");
    }

    I hope this helps.

    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
  5. John Hadjioannou
    John Hadjioannou avatar
    30 posts
    Member since:
    Dec 2005

    Posted 18 Aug 2010 Link to this post

    Thanks, Simon

    I had to add a check:

    eventArgs.get_domEvent() != null


    but apart from that it did the trick.

    John
Back to Top