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

Showing Dropdown On TextChanged

6 Answers 443 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 18 Jun 2009, 04:11 PM
I've been working on and and searching the forums concerning showing the dropdown of the combobox after the server-side TextChanged event has fired.  It has turned out to be trickier than I originally thought.  Is there an easy to do this that I'm overlooking?

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jun 2009, 07:37 AM
Hi David,

Here is the code snippet that I tried in order to show dropdown after TextChanged event is fired.

CS:
 
protected void RadComboBox2_TextChanged(object sender, EventArgs e) 
    string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(showDropdown);</script>"
    ClientScript.RegisterStartupScript(this.GetType(), "showDropdown", script);   

ASPX:
 
<telerik:RadComboBox ID="RadComboBox2" AllowCustomText="true" runat="server" AutoPostBack="True" OnTextChanged="RadComboBox2_TextChanged"
    <Items> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" /> 
    </Items> 
</telerik:RadComboBox> 

JavaScript:
 
<script type="text/javascript"
function showDropdown() 
    var combo = $find("<%= RadComboBox2.ClientID %>"); 
    combo.showDropDown(); 
</script> 

Thanks,
Shinu.
0
David
Top achievements
Rank 1
answered on 19 Jun 2009, 01:04 PM
Shinu,

Thanks for the reply.  Unfortunately, I had already tried that and it did not work.  The problem is that I've wrapped my combobox in a user control which is then placed on a webform.  The client-side code to handle showing the drop is in the user control, and like your example, I figured it would be as easy as adding a call to the proper client-side function to show the drop down.  Unfortunately, I ran into what seems to be a common problem with the rad controls:  Adding script via the RegisterClientScriptBlock() or RegisterStartupScript() methods emits the client-side code before the embedded client-side code that initializes the telerik objects.  This results in calls to $find() returning null references.

For anyone who has this problem, I solved it by hooking into the RadCombo.OnClientLoad event.  I placed the following code snippet into the server-side Page_Load event of my user control.  This code emits client-side code that will load the combo into a variable declared outside of a function and thus available to other functions:

ScriptManager.RegisterClientScriptBlock(this, Page.GetType(), "GetCombo""var combo; function  OnClientLoad(sender){ combo = sender;}"true); 

Then later in my server-side TextChanged event handler, I utilize the ResponseScripts.Add() method of a RadAjaxManager to emit client-side code to access the combo var that was initialized in the code block above:

ajaxManager.ResponseScripts.Add("combo.showDropDown();"); 

I admit that it's a little hokey, but I have verified that it works in both FF and IE and is the best way that I can see to get around the timing issue of when the ScriptManager object emits its client-side code versus when the embedded client-side code to initialize the telerik objects is emitted.

What would be very helpful would be server-side methods included with some of these Rad controls that would emit such client-side code automatically.  For instance, a server-side method called RadCombo.ShowDropDown() that would encapsulate a lot of this work.

Anyway, I hope this helps someone else, and if anyone else knows of a more reliable or easy-to-read way, please don't hesitate to post it.


0
Veselin Vasilev
Telerik team
answered on 22 Jun 2009, 08:23 AM
Hello David,

We have a property called OpenDropDownOnLoad. When set to True - it will automatically show the dropdown when the page is loaded.

Sincerely yours,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
David
Top achievements
Rank 1
answered on 22 Jun 2009, 01:41 PM
Veseli,

I did see the property that you mentioned, but unfortunately, I don't want the drop down to show ever Page_Load.  I only want the drop down to show when the user presses the "Enter" key, a search is fired, and more than one result is returned.
0
Accepted
Veselin Vasilev
Telerik team
answered on 25 Jun 2009, 08:58 AM
Hi David,

Then set that property in the click event handler of your button (not in Page_Load).

Regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
David
Top achievements
Rank 1
answered on 29 Jun 2009, 07:32 PM
Thanks, that worked!
Tags
ComboBox
Asked by
David
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or