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

Detecting click on image in RadComboBox

8 Answers 154 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Warnestam
Top achievements
Rank 1
Warnestam asked on 18 Aug 2008, 03:30 PM
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

8 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 18 Aug 2008, 03:41 PM
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.
0
Warnestam
Top achievements
Rank 1
answered on 18 Aug 2008, 03:55 PM
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.
0
Warnestam
Top achievements
Rank 1
answered on 20 Aug 2008, 11:54 AM
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?
0
Veselin Vasilev
Telerik team
answered on 20 Aug 2008, 02:53 PM
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.
0
Warnestam
Top achievements
Rank 1
answered on 20 Aug 2008, 06:32 PM

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.

0
Warnestam
Top achievements
Rank 1
answered on 21 Aug 2008, 07:13 PM
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
0
Accepted
Veselin Vasilev
Telerik team
answered on 22 Aug 2008, 03:09 PM
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.
0
Warnestam
Top achievements
Rank 1
answered on 24 Aug 2008, 05:15 PM
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
Tags
ComboBox
Asked by
Warnestam
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Warnestam
Top achievements
Rank 1
Share this question
or