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

Clicking the Button when i select RadComboBox

4 Answers 221 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
nazeer
Top achievements
Rank 1
nazeer asked on 08 Jun 2012, 11:51 AM
Hi TelerikTeam,

I have a RadCombobox,when selecting the item in the RadCombobox and click on enter button,i need to trap Click event of the 'btnGo' Button event.

 

<telerik:RadComboBox ID="rcbTest" runat="server" Width="200px" Skin="Web20" AllowCustomText="true" MarkFirstMatch="true" AutoPostBack="true" OnSelectedIndexChanged="rcbTest_OnSelectedIndexChanged">
    <Items>
        <telerik:RadComboBoxItem Text="Test1" Value="1" />
        <telerik:RadComboBoxItem Text="Test2" Value="2" />
        <telerik:RadComboBoxItem Text="Test3" Value="3" />
        <telerik:RadComboBoxItem Text="Test4" Value="4" />
        <telerik:RadComboBoxItem Text="Test5" Value="5" />
    </Items>
</telerik:RadComboBox>
  
<asp:Button ID="btnGo" runat="server" Text=" Go " Width="75px"  OnClick="btnGo_Click"/>

Please tell me how can i acheive this scenario.

Thank You
Shaik Nazeer Hussain

 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Jun 2012, 05:26 AM
Hello,

One suggestion is you can place the controls inside a panel as shown and set the DefaultButton of that panel as btnGo. Here is the sample code.
ASPX:
<asp:Panel ID="Panel1" runat="server" DefaultButton="btnGo">
<telerik:RadComboBox ID="rcbTest" runat="server" Width="200px" Skin="Web20" AllowCustomText="true" MarkFirstMatch="true" AutoPostBack="true" OnSelectedIndexChanged="rcbTest_SelectedIndexChanged">
     <Items>
          <telerik:RadComboBoxItem Text="Test1" Value="1" />
          <telerik:RadComboBoxItem Text="Test2" Value="2" />
          <telerik:RadComboBoxItem Text="Test3" Value="3" />
          <telerik:RadComboBoxItem Text="Test4" Value="4" />
          <telerik:RadComboBoxItem Text="Test5" Value="5" />
    </Items>
 </telerik:RadComboBox>
<asp:Button ID="btnGo" runat="server" Text="Remove" OnClick="btnGo_Click" />
</asp:Panel>
C#:
protected void rcbTest_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
   {
       rcbTest.Focus();//to set focus after selecting an item
   }

Thanks,
Princy.
0
nazeer
Top achievements
Rank 1
answered on 11 Jun 2012, 09:05 AM
Hi,

In my scenario it is not working and my code is as follows.

C#
protected
void rcbTest_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) 
   
       rcbTest.Attributes.Add("onkeypress", "return controlEnter('" + btnGo.ClientID + "')");    
    
    
.Aspx
function controlEnter(obj)  
  {  
       var keyCode = event.keyCode; 
          if (keyCode == 13)  
          {  
                        document.getElementById(obj).click();  
                        return false;  
          }  
   
        else
        {  
                        return true;  
        }  
    }


Please let me know if you need more info.


ThankYou
Shaik Nazeer Hussain
0
Shinu
Top achievements
Rank 2
answered on 14 Jun 2012, 09:23 AM
Hi Nazeer,

Here is the sample code I tried based on your scenario which works as expected at my end.

JS:
<script type="text/javascript" >
function OnClientKeyPressing(sender, args)
        {
            if (args._domEvent.keyCode == 13)
            {
                var btn = document.getElementById("btnGo");
                btn.click();
            }
        }
</script>

Hope this helps.

Thanks,
Shinu.
0
nazeer
Top achievements
Rank 1
answered on 18 Jun 2012, 05:14 AM
Hi Shinu,

When i am clicking on enter button inside the rcbTest Combobox, even it is not firing at client side.Because for RadcomboBox i have enabled all the following properties.

AllowCustomText="true" MarkFirstMatch="true" AutoPostBack="true"

 


Please let me know if you need more information.

ThankYou
Shaik Nazeer Hussain
Tags
ComboBox
Asked by
nazeer
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
nazeer
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or