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

get_value() issue

2 Answers 202 Views
Input
This is a migrated thread and some comments may be shown as answers.
Bernard
Top achievements
Rank 1
Bernard asked on 25 Feb 2013, 10:46 AM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Feb 2013, 12:19 PM
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.
0
Bernard
Top achievements
Rank 1
answered on 26 Feb 2013, 07:02 AM

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

Tags
Input
Asked by
Bernard
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bernard
Top achievements
Rank 1
Share this question
or