Can I cancel the ValueChange event at client side?

4 posts, 0 answers
  1. Jeffery
    Jeffery avatar
    18 posts
    Member since:
    Sep 2006

    Posted 25 Mar 2008 Link to this post

    Dear support,

    I need be able to cancel the Slide change in some condition.  I have try the following code:

    function HandleClientValueChange(sender, eventArgs) {
     var ok = false;
     // Do some caculation
     if(!ok) {
      sender.set_Value(eventArgs.get_oldValue());
      return;
     }
    }

    Unfortunatly it does not work.  Is there any way I can cancel out slider's change at client side?

    Thanks,
    Jeffery
  2. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 26 Mar 2008 Link to this post

    If you handle OnClientSlideStart and OnClientSlideEnd events you will achieve your goal. E.g.:
    <head runat="server">  
        <title>Untitled Page</title> 
        <script type="text/javascript">  
             var oldValue;  
             function OnClientSlideStart(currentSlider,args)  
             {              
              oldValue = currentSlider.get_value();  
                 
             }  
             function OnClientSlideEnd(currentSlider,args)  
             {  
                var ok = false;  
                if(!ok)  
                {  
                    currentSlider.set_value(oldValue);  
                }   
             }  
        </script> 
          
          
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
        <div> 
        <telerik:RadSlider ID="RadSlider1" runat="server"   
        MinimumValue="0" MaximumValue="400" 
        OnClientSlideEnd = "OnClientSlideEnd" 
        OnClientSlideStart = "OnClientSlideStart" 
        /> 
        </div> 
        </form> 
    </body> 
    </html> 
     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeffery
    Jeffery avatar
    18 posts
    Member since:
    Sep 2006

    Posted 26 Mar 2008 Link to this post

    Thanks.  It works when I drag the handler.  Unfortunately it dose not work when I use Increase and Decrease handlers or just click on the slider.
  5. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 31 Mar 2008 Link to this post

    I managed to handle all scenarios with the OnClientValueChange event:
    <head runat="server">  
        <title>Untitled Page</title> 
        <script type="text/javascript">  
             var isSecond = false;  
             function OnClientValueChange(currentSlider,args)  
             {  
               if(isSecond == false)  
               {  
                var oldValue = args.get_oldValue();  
                //Tthis flag is used because set_value will fire the ClientValueChange event again  
                isSecond = true;  
                currentSlider.set_value(oldValue);             
               }  
               else  
               {  
               isSecond = false;  
               }  
                 
             }  
        </script> 
          
          
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
        <div> 
        <telerik:RadSlider ID="RadSlider1" runat="server"   
        MinimumValue="0" MaximumValue="400" 
        Value = "50" 
        OnClientValueChange = "OnClientValueChange"   
        /> 
        </div> 
        </form> 
    </body> 
    </html> 
Back to Top