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

RadTextBox not passing arguments to client-side function

2 Answers 248 Views
Input
This is a migrated thread and some comments may be shown as answers.
Joaquín
Top achievements
Rank 2
Joaquín asked on 26 Feb 2012, 02:54 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 28 Feb 2012, 12:56 PM
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.
0
Joaquín
Top achievements
Rank 2
answered on 28 Feb 2012, 06:20 PM
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.


Tags
Input
Asked by
Joaquín
Top achievements
Rank 2
Answers by
Vasil
Telerik team
Joaquín
Top achievements
Rank 2
Share this question
or