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

problem with function GetSlider()

2 Answers 37 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Jan
Top achievements
Rank 1
Jan asked on 26 Oct 2009, 12:01 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetie
Telerik team
answered on 28 Oct 2009, 03:54 PM
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.
0
Jan
Top achievements
Rank 1
answered on 28 Oct 2009, 04:01 PM
Thanks, you are the best!
Tags
Slider
Asked by
Jan
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Jan
Top achievements
Rank 1
Share this question
or