Define onClientKeyPressed via JavaScript in pageLoad

3 posts, 1 answers
  1. Matt
    Matt avatar
    78 posts
    Member since:
    Mar 2009

    Posted 08 Jun 2015 Link to this post

    How can I add an event handler via JavaScript in pageLoad to handle the keyPress event of a RadComboBox? 

    We create a series of ComboBox controls dynamically based on user preferences.  We want to be able to accept user keystrokes and when they press the Enter key, fire the rrKeyPress event.

    We're unable to define this in our code due to business constraints; it *MUST* be in JavaScript on pageLoad.

    I've tried adding it using the code below, but it didn't work as expected:

    // Loop through controls and attach

    var comboBox = document.getElementById('RadComboBox1');
    comboBox.add_valueChanged(rrKeyPress);

    Any suggestions?

  2. Answer
    Plamen
    Admin
    Plamen avatar
    2733 posts

    Posted 10 Jun 2015 Link to this post

    Hello,

    Here is the code that worked correctly at my side:
    <script type="text/javascript">
     
              function pageLoad() {
                  var combo = $find("<%=RadComboBox1.ClientID%>");
                  combo.add_keyPressing(
                      function(sender, args) {
                          alert(args.get_domEvent().keyCode);
                      });
              }
          </script>
          <div>
              <telerik:RadComboBox runat="server" ID="RadComboBox1">
                  <Items>
                      <telerik:RadComboBoxItem Text="aaa" />
                      <telerik:RadComboBoxItem Text="bbb" />
                      <telerik:RadComboBoxItem Text="ccc" />
     
                  </Items>
     
              </telerik:RadComboBox>
          </div>

    Hope this will help you solve the issue.

    Regards,
    Plamen
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matt
    Matt avatar
    78 posts
    Member since:
    Mar 2009

    Posted 11 Jun 2015 in reply to Plamen Link to this post

    Thanks...worked like a champ!
Back to Top