RadTextBox not passing arguments to client-side function

3 posts, 1 answers
  1. Joaquín
    Joaquín avatar
    27 posts
    Member since:
    Jan 2012

    Posted 25 Feb 2012 Link to this post

    I have this RadTextBox:
    <asp:panel id="div_projectsAssigned" runat="server" class="infoBox-projectsAssigned">
            <telerik:RadTextBox ID="txtProjectsAssigned" runat="server" Text="0"
                       BorderStyle="None" ReadOnly="True" Width="42" >
                        <ClientEvents OnValueChanged="onValueChanged()" />
                        <ReadOnlyStyle HorizontalAlign="Center" BackColor="Transparent" ForeColor="White"
                                Font-Bold="True" Font-Names="Segoe UI" Font-Size="12pt" Width="30px">
                         </ReadOnlyStyle>
           </telerik:RadTextBox>
    </asp:panel>

    Note the parenthesis on

    ClientEvents OnValueChanged="onValueChanged()" />


    If I remove the parenthesis from the function call, the function is not executed. If I keep the parenthesis, the function is executed (see below), but the parameters are not passed.
    <script type="text/javascript">
     
            function onValueChanged(sender, args) {
     
                if (args.get_oldvalue != args.get_newvalue) {
     
                    thisDiv = $get("<%= div_projectsAssigned.ClientID %>");
                    esteDiv = "#" + thisDiv;
                    animateDiv(thisDiv);
                }
            }
     
            function animateDiv(divToAnimate) {
     
                for (i = 1; i <= 3; i++) {
     
                    $(divToAnimate).animate(
                        { "opacity": "0.15" },
                        "slow");
     
                    $(divToAnimate).animate(
                        { "opacity": "1.00" },
                        "slow");
                }
            }
     
        </script>

    I need the parameters to check if the value in the RadTextBox has changed, and if so, make an amimation.
    Any idea about why the parameters are not being passed?
  2. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 28 Feb 2012 Link to this post

    Hi Joaquín,

    You should pass the name of the function without the parentheses.

    How do you change the value of the TextBox? In your code it is declared as ReadOnly, so the user can not edit the value and this means that the OnValueChanged event will not be fired. It is fired when the text changes.
    I tested it with changing the value using the set_value() client function of the RadTextBox. and the onValueChanged is fired with correct arguments.

    Note that there is also an error in your code. This line:
    args.get_oldvalue !=args.get_newvalue
    Should be:
    args.get_oldValue() != args.get_newValue()

    Here is demonstration how to properly attach the handler and check the values:
    <script type="text/javascript">
      function onValueChanged(sender, args)
      {
        if (args.get_oldValue() != args.get_newValue())
        {
          alert("change");
        }
      }
    </script>
    <telerik:RadTextBox ID="txtProjectsAssigned" runat="server" ReadOnly="True">
      <ClientEvents OnValueChanged="onValueChanged" />
    </telerik:RadTextBox>
    <input type="button" onclick="$find('txtProjectsAssigned').set_value(new Date()) ; return false;" />


    All the best,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joaquín
    Joaquín avatar
    27 posts
    Member since:
    Jan 2012

    Posted 28 Feb 2012 Link to this post

    Hi Vasil, thank you for your answer.

    I was changing the value of the textbox from code behind (within an ajax request) every time a Timer control ticked (thats why it is read only). I supossed that it would fire the OnValueChanged event.

    Anyway, I have changed the approach now and I call the js function from the code behind using

    RadAjaxManager1.ResponseScripts.Add method when the value changes, and everything runs smooth.

    I will check the textbox OnValueChanged event in a "normal" scenario as the one you have posted to see if it works properly here.


Back to Top