Slider Additional arguments in OnClientValueChange

4 posts, 1 answers
  1. Dave Myers
    Dave Myers avatar
    47 posts
    Member since:
    Sep 2008

    Posted 20 Mar 2009 Link to this post

    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.
  2. Answer
    Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 24 Mar 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dave Myers
    Dave Myers avatar
    47 posts
    Member since:
    Sep 2008

    Posted 24 Mar 2009 Link to this post

    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
  5. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 24 Mar 2009 Link to this post

    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.
Back to Top