get_value() issue

3 posts, 0 answers
  1. Bernard
    Bernard avatar
    41 posts
    Member since:
    Jun 2010

    Posted 25 Feb 2013 Link to this post

    Hello,
    I have upgraded the telerik version from 2011-02 to 2012_03.

    In my code behind, I set the ClientEvents.OnKeyPress value. Until the upgrade, it worked very well. But since it doesn't. it seems that the get_value() needs a delay to return the value. If I replace the get_value by document.getElementById, it works...

    I would rather like to use the get_value() function.
    Thanks for help...
    Bernard

    saisie.ClientEvents.OnKeyPress = @"enterSaisie2";
    function pageLoad() 
            {
               textSaisie = $find("<%=saisie.ClientID %>");
            
    function enterSaisie2(e)
            {
               if (window.event.type == "keypress" && window.event.keyCode == 13) 
               {
                    try
                    {
                        aSaisie = new String(textSaisie.get_value());
                                       // etc...
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Feb 2013 Link to this post

    Hi Bernard,

    Please take a look into the following code snippet I tried with RadTextBox, since  you havent specified which control you are using. During the OnKeyPress event the value is still not updated, therefore, sender.get_value() will return the old one. So if you want to get the newly typed value from the RadTextBox on OnKeyPress event, please try the following.

    ASPX:
    <telerik:RadTextBox ID="TextBox1" runat="server" Text="old value" onKeyPress="return enterSaisie2(event);"></telerik:RadTextBox>

    JavaScript:
    <script type="text/javascript">
        function enterSaisie2(e) {
            if (window.event.type == "keypress" && window.event.keyCode == 13) {
                textSaisie = $find("<%=TextBox1.ClientID %>");
               // you will get the old value in TextBox here
               var aSaisie = textSaisie.get_value();
               
              // you will get the newly typed value here
              var aSaisie = textSaisie.get_element().value;
            }
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bernard
    Bernard avatar
    41 posts
    Member since:
    Jun 2010

    Posted 26 Feb 2013 Link to this post

    Hello Princy,

    Many thanks for your answer. Sorry not to have specified the control. You guessed that it was a RadTextBox.

    But if I understand, the behaviour of this function has changed. Otherwise it wouldn't have worked with the previous version.
    Anyway, your explanation is clear. So I'm going to do like you advocate.
    Have a good day...
    Bernard

Back to Top