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

Slider Additional arguments in OnClientValueChange

3 Answers 95 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Dave Myers
Top achievements
Rank 1
Dave Myers asked on 20 Mar 2009, 04:27 PM
I am using the slider control in a repeater with a label on either side of each slider.  I need to do some calculations and update the labels accordingly.  The problem is that I have no way of supplying the clientId's of the labels or passing any variables (that I know of).  I tried adding a onMouseOver event to set variables, but the problem is that it keeps getting called (multiple times) and messing up the actual onClientValueChange function i have written.  Is there any way of supplying additional parameters in these methods?  I am also fine with setting them beforehand using a seperate function if that works but would like to only do it once.

3 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetie
Telerik team
answered on 24 Mar 2009, 03:08 PM
Hello Dave Myers,
As far as I understand you, you would like to get a reference to the Label, associated with the RadSlider in the OnClientValueChange handler of the slider control. If this is the case, you can use any approach with the RadSlider as with a standard ASP Button control (in the OnClientClick handler).

The easiest way would be to use a convention for the IDs of the Controls. For example:
  • RadSlider1 -> RadSliderLabel1
That way, you can find the ClientID of the Label, using the ClientID of the RadSlider - simply replace the "RadSlider1" substring in the ClientID of the RadSlider with "RadSliderLabel1". You can get the ClientID of the RadSlider control using the get_id() client-side method:
var sliderClientID = slider.get_id(); 

Apart from this, you can add an Attribute to the RadSlider control with a value of the ClientID of the Label, associated with that RadSlider. Then, in the OnClientValueChange handler, you can get that value, using the following syntax:
slider.get_element().getAttribute('labelClientID'); 

Regards,
Tsvetie
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Dave Myers
Top achievements
Rank 1
answered on 24 Mar 2009, 03:37 PM
The second option is more of what i was looking for and seems like there is less room for error that way.  I tested it and it works fantasically!  Thanks for the help.  The only question i would have is if using this method to add/get attributes is common amongst all the telerik controls.  If so, this saves me a lot of hassle of creating and setting global javascript variables. 

Thanks again
0
Tsvetie
Telerik team
answered on 24 Mar 2009, 04:40 PM
Hello Dave Myers,
Generally, this approach would work for most of our controls. Actually, the approach is not connected to our controls at all. An attribute is rendered as an attribute of the outermost HTML element of a control and the getAttribute client-side method is a method of an HTML element, not of a telerik client-side object. Some of our controls however control the attributes they render (e.g. they do not render custom attributes at all) and the approach would not work for them - for example, such a control is the RadSplitter control.

Basically, you can test whether you can use this approach with a control quickly, just by placing a similar declaration in an ASPX page to the following:
<telerik:[RadControl] ID="RadControl1" runat="server" test="test"></ telerik:[RadControl]> 

After that, you can check the outermost element that the control has rendered for that attribute using IE DevToolBar or FireBug for example. I have attached a screenshot of the IE DevToolBar console that demonstrates the result for a RadSlider:
<telerik:RadSlider ID="RadSlider1" runat="server" test="test"
</telerik:RadSlider> 

Best wishes,
Tsvetie
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Slider
Asked by
Dave Myers
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Dave Myers
Top achievements
Rank 1
Share this question
or