RadTextBox: set_value and onchange create Loop

3 posts, 0 answers
  1. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 05 Mar 2012 Link to this post

    My RadTextBox has the onchange value set. When the user enters a value, I look up a value on our DB, which returns a value, with which I use set_value to either blank out the RadTextBox or assign it a different value.

    But when I use set_value for either reason, it kicks off the onchange event again, creating a loop, which calls our DB 100's of times before finally stopping. How can I prevent that?
  2. Vasil
    Vasil avatar
    1642 posts

    Posted 08 Mar 2012 Link to this post

    Hi Jeremy,

    The OnValueChanged event should be fired every time when you use set_value() method. So to avoid recursion you just need to set some flag that to change when handling the event. See the code-snippet below:

    <script type="text/javascript">
      function valueChanged(sender, args)
        if (sender.internalValueSet)
          //this time the event was fired because changing the value manually
          var value = args.get_newValue();
          //make make some call to your database..
          var changedValue = "some new value";
          sender.internalValueSet = true;
          sender.internalValueSet = false;
    <telerik:RadTextBox runat="server" ClientEvents-OnValueChanged="valueChanged">

    I hope this helps.

    All the best,
    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. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 09 Mar 2012 Link to this post

    That's what I started doing to get around it, but I guess I was hoping for something a bit more elegant. Thanks.
Back to Top