Clicking the Button when i select RadComboBox

5 posts, 0 answers
  1. nazeer
    nazeer avatar
    27 posts
    Member since:
    May 2009

    Posted 08 Jun 2012 Link to this post

    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

     

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

    Posted 11 Jun 2012 Link to this post

    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.
  3. nazeer
    nazeer avatar
    27 posts
    Member since:
    May 2009

    Posted 11 Jun 2012 Link to this post

    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
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jun 2012 Link to this post

    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.
  5. nazeer
    nazeer avatar
    27 posts
    Member since:
    May 2009

    Posted 18 Jun 2012 Link to this post

    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
Back to Top