problem with function GetSlider()

3 posts, 1 answers
  1. Jan
    Jan avatar
    37 posts
    Member since:
    May 2008

    Posted 25 Oct 2009 Link to this post

    Hi, I have a code snippet:

    function GetSlider() { 
      return $find("<%= RadSlider1.ClientID %>"); 
     
    var radSlider = GetSlider(); 
     
    alert(radSlider); 
     
    var newValue = $.cookie('site_font_size'); 
     
    newValue = newValue.substring(0, newValue.length-2) 
    radSlider.set_value(newValue * 10); 

    in alert window i get [null] and script failed to load after radSlider.set_value(newValue * 10);

    i tried use Jquery selector by id, but that returns bad object i think. I'm not very skilled in JavaScript, so don't laugh :)

    radSlider I have defined with

    <telerik:RadSlider ID="RadSlider1" runat="server"  OnClientValueChange="valueChanged" MinimumValue="3" MaximumValue="15"


    Any ideas?







  2. Answer
    Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 28 Oct 2009 Link to this post

    Hi Jan,
    Your javascript code is correct. The problem is in the time when you execute it. The client objects for the controls are created during the  Sys.Application.init event and your code executes before that. That is why you cannot get a reference to the RadSlider control - it has not been created yet. You can read mode about the client lifecycle in MSDN.

    You have two options:
    1. Execute the script during the Sys.Application.load event:
      function pageLoad()
      {
          var radSlider = GetSlider();
       
          alert(radSlider);
       
          var newValue = $.cookie('site_font_size');
       
          newValue = newValue.substring(0,newValue.length - 2)
          radSlider.set_value(newValue * 10);
      }
    2. Execute the script right after the RadSlider is initialized:
      <telerik:RadSlider ID="RadSlider1" runat="server"
          MinimumValue="3" MaximumValue="15" OnClientLoaded="OnClientLoaded">
      function OnClientLoaded(sender, args)
      {
          var radSlider = GetSlider();
       
          alert(radSlider);
       
          var newValue = $.cookie('site_font_size');
       
          newValue = newValue.substring(0,newValue.length - 2)
          radSlider.set_value(newValue * 10);
      }
    Best wishes,
    Tsvetie
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jan
    Jan avatar
    37 posts
    Member since:
    May 2008

    Posted 28 Oct 2009 Link to this post

    Thanks, you are the best!
Back to Top