Detecting click on image in RadComboBox

9 posts, 1 answers
  1. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 18 Aug 2008 Link to this post

    Hi,

    I'm using a RadComboBox control to search for and display records. On the server the ItemsRequested method is returning data based on the input text.

    The user can also click the RadComboBox image to perform a search and here comes the tricky part. I would like detect on the server if the event is caused by entering text or clicking the image. The reason to this is that I want to perform a custom search and a default search, where the default search is done with no input text. 

    Thanks

    Robert
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Aug 2008 Link to this post

    Hi Warnestam,

    I think the easiest way is to check the e.Text in ItemsRequested event handler:

    if (e.Text == string.Empty)  
    {  
     //default search goes here  
    }  
    else 
    {  
      //custom search goes here  


    Greetings,
    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. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 18 Aug 2008 Link to this post

    Unfortunatly it's not that easy. I'm displaying the the selected record in the RadComboBox (setting the SelectedValue and Text propery of the control) and this means that in the ItemsRequested event the e.Text is set to the text for this object. My problem is thatI would like to know if the user clicks on the image, and in that case perform a default search, and this can't be done with your suggestion because the e.Text is not empty.
  5. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 20 Aug 2008 Link to this post

    Still no working solution...

    If there is a way to clear the text in the RadComboBox before generating the ItemsRequested event IF the user clicks on the image, then I think that would solve the problem.

    But how do I detect the click on the image?
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 20 Aug 2008 Link to this post

    Hi Warnestam,

    Here is how you can attach a click event for the image of the combobox:

    <script type="text/javascript"
    function pageLoad() 
        var combo = $find("<%= RadComboBox1.ClientID %>"); 
        var image = combo.get_imageDomElement(); 
        image.onclick = onComboImageClick; 
     
    function onComboImageClick() 
        alert("image was clicked"); 
    </script>  

    In the onComboImageClick you can set the value of a hidden field to something, and then check this value in the ItemsRequested server-side event.

    I hope this helps.

    All the best,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 20 Aug 2008 Link to this post

    It almost worked this time :) It seems however that the clic event fires to late.

    My RadComboBox:

    <telerik:RadComboBox ID="rcbSearchValue" runat="server"   
                    AllowCustomText="True"   
                    EnableLoadOnDemand="True" 
                    OnSelectedIndexChanged="rcbSearchValue_SelectedIndexChanged"   
                    SkinID="SearchSkin" 
                    HighlightTemplatedItems="True"   
                    NoWrap="True"   
                    ItemRequestTimeout="1000"   
                    ShowMoreResultsBox="true" 
                    OnItemsRequested="rcbSearchValue_ItemsRequested"                                      OnClientItemsRequesting="MyOnClientItemsRequesting" 
                    OnClientLoad="MyOnClientLoad">  
                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                    <ItemTemplate> 
                        <%# GetTextForDataItem(Container) %> 
                    </ItemTemplate> 
                </telerik:RadComboBox> 

    And the script that will clear thesearch text when the image is clicked;

    <script type="text/javascript">  
    function MyOnClientItemsRequesting(sender,e)  
    {  
        if (sender.get_appendItems() == true)  
        {  
            e.set_cancel(true);  
        }  
    }  
     
    var  combo<%= rcbSearchValue.ClientID %>;  
    function MyOnClientLoad(sender)    
    {    
        combo<%= rcbSearchValue.ClientID %> = sender;  
        var image = sender.get_imageDomElement();    
        image.onclick = onComboImage<%= rcbSearchValue.ClientID %>Click;    
    }    
        
    function onComboImage<%= rcbSearchValue.ClientID %>Click()    
    {    
        combo<%= rcbSearchValue.ClientID %>.set_text("xxx");  
    }    
     
    </script> 

    I have checked that the javascript is called correctly, but the change of the text in the RadComboBox does not goesto the server.

  8. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 21 Aug 2008 Link to this post

    No solution yet...

    Just tried another aproach, settin a local variable in tje javascript when the Image was clicked, then on the ItemsRequested event I looked at it and tried to use it there. Still, it seems like the image click event comes to late...

    Any help is welcome
  9. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 22 Aug 2008 Link to this post

    Hello Warnestam,

    I have prepared a sample project for you. Please download it and give it a try.

    I hope this helps.

    All the best,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 24 Aug 2008 Link to this post

    Thanks Veskoni,

    I was trying to change the text on the client witout luck But your suggestion to use the context helped me to solve the problem.

    Thanks again

    Robert
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017