Getting Value after post back

8 posts, 0 answers
  1. Voss Grose
    Voss Grose avatar
    81 posts
    Member since:
    Sep 2012

    Posted 25 Jan 2009 Link to this post

    I've posted this before, but the solution did not work.

    I cannot get the value of the selected item in the slider control on post back.
    I just give me the index of the selected item.

    I must have some strange setting or doing something crazy because this must work:
    Below is the slider control I've used for testing and on a simple button click (server side) I cannot get the correct value. Just gives me the index.

    I'm using the latest version of the telerik controls.

                                                    <telerik:RadSlider runat="server" ID="rsVery" EnableViewState="true" Orientation="Horizontal" Width="500" Height="50" TrackPosition="TopLeft" Skin="Inox" ItemType="Item" SmallChange="1" ShowDecreaseHandle="true" ShowIncreaseHandle="true" AnimationDuration="250">
                                                        <Items>
                                                            <telerik:RadSliderItem Text="Very Slow" Value="22" ToolTip="Very Slow" runat="server"></telerik:RadSliderItem>
                                                            <telerik:RadSliderItem Text="Slow" Value="33" runat="server"></telerik:RadSliderItem>
                                                            <telerik:RadSliderItem Text="Normal" Value="44" runat="server"></telerik:RadSliderItem>
                                                            <telerik:RadSliderItem Text="Fast" Value="55" runat="server"></telerik:RadSliderItem>
                                                            <telerik:RadSliderItem Text="Very Fast" Value="66" runat="server"></telerik:RadSliderItem>
                                                        </Items>
                                                    </telerik:RadSlider>
  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 26 Jan 2009 Link to this post

    Hello Voss Grose,
    As already mentioned in the other thread you started with the same question, the Value property of the RadSlider gets the index of the selected item, when you use ItemType=Item. This is by design and we decided to implement the RadSlider that way, so that you can set not only integers as Value for a RadSlider item, but strings as well. When you get the index of the selected item, you can use it to get a reference to the item itself and then get its Value.

    For example (this code was posted in the other forum thread and demonstrated what you need to do in VB):
    Dim slider As RadSlider = TryCast(item.FindControl("rslider"), Telerik.Web.UI.RadSlider) 
    Dim value As Integer = slider.Value 
    Dim routsegid As String = slider.Items(value).Value.ToString() 

    or:
    int value = rsVery.Value; 
    string routsegid = rsVery.Items[value].Value; 

    In case you still have problems getting the value of the selected item, please prepare and send us a simple running project, demonstrating the problem, together with detailed information on the expected result.

    Kind 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. Voss Grose
    Voss Grose avatar
    81 posts
    Member since:
    Sep 2012

    Posted 30 Jan 2009 Link to this post

    Thanks for the reply, but I still do not understand why it's implemented in this fashion.

    An asp DropDownList(like many controls) has a selectedvalue as type String.

    Why wouldn't the slider work the same way?

    It seems as though it should always return a string and it should be up to the developer to convert the value.

    Maybe I'm not understanding something...but it seems kind of a hack to have to retrieve the value in this manner.
  5. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 02 Feb 2009 Link to this post

    Hi Voss Grose,
    Besides the reason, I have already provided in the other forum thread, namely:
    ***
    We made this on purpose, so that the developers have more flexibility and can define sliders like the following one:
    <telerik:RadSlider ID="MonthsSlider" runat="server" Orientation="Vertical" Skin="SkyBlue" 
        Height="417px" Width="100px" CssClass="monthsSlider" ItemType="Item" TrackPosition="TopLeft" 
        Value="5" OnClientValueChange="MonthChange"
        <Items> 
            <telerik:RadSliderItem Text="January" Value="Jan" /> 
            <telerik:RadSliderItem Text="February" Value="Feb" /> 
            <telerik:RadSliderItem Text="March" Value="Mar" /> 
            <telerik:RadSliderItem Text="April" Value="Apr" /> 
            <telerik:RadSliderItem Text="May" Value="May" /> 
            <telerik:RadSliderItem Text="June" Value="Jun" /> 
            <telerik:RadSliderItem Text="July" Value="Jul" /> 
            <telerik:RadSliderItem Text="August" Value="Aug" /> 
            <telerik:RadSliderItem Text="September" Value="Sep" /> 
            <telerik:RadSliderItem Text="October" Value="Oct" /> 
            <telerik:RadSliderItem Text="November" Value="Nov" /> 
            <telerik:RadSliderItem Text="December" Value="Dec" /> 
        </Items> 
    </telerik:RadSlider> 

    ***

    , our decision was based on the following ones as well:

    1. The RadSlider should work in a consistent way:
      1. It should return only Integers when it has ItemType=None. That is why it should return an Integer, no matter what the value of the ItemType property is.
      2. The MinumumValue, MaximumValue and SmallChange, which are all of Int type, should have meaning even in case ItemType=Item.
    2. The RadSlider should be backwards compatible - otherwise, we will break the code of our customers in case they decide to upgrade. As the Value property was of type Int before we implemented the ItemType property, we would not change its type. This is not applicable in case the change is a must, which is not the case.
    3. Even though the RadSlider resembles a DropDownList in many ways, in this particular case, the DropDownList lacks the features that the RadSlider has, based on which we have decided to implement the Value property in this manner.

    Best wishes,
    Tsvetie
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Voss Grose
    Voss Grose avatar
    81 posts
    Member since:
    Sep 2012

    Posted 07 Feb 2009 Link to this post

    Follow up:

    How do I set the value?

    So I get the value back from a Db...how do I set the value of a slider control?
    thanks.
  7. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 10 Feb 2009 Link to this post

    Hello Voss Grose,
    You can set the value of the RadSlider control using its Value property. In case you get the value of the RadSliderItem, you will have to get the index of that item and set it as Value of the RadSlider.

    All the best,
    Tsvetie
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Voss Grose
    Voss Grose avatar
    81 posts
    Member since:
    Sep 2012

    Posted 10 Feb 2009 Link to this post

    Can you please give me a code exmaple of setting the value?
    I've tried it using the index, but it dose not work for me.

    I would like an example for the following:
    Slider with the following items (-10, -5. 0, 5, 10)
    Obviously I'm not going to store the index in the Db so I'll store "5" (selected value)
    In the code I'll retrive "5" from the Db and locate the index as 3.
    It's the actual setting of the value I cannot get to work.
    Do not worry about what my code looks like...I would like a working example if you could provide it.

    thanks.
  9. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 13 Feb 2009 Link to this post

    Hello,
    Have a look at the following code fragment:
    <telerik:RadSlider ID="RadSlider1" runat="server"  
        ItemType="Item" Height="70px" TrackPosition="TopLeft"
        <Items> 
            <telerik:RadSliderItem Text="-10" Value="-10" /> 
            <telerik:RadSliderItem Text="-5" Value="-5" /> 
            <telerik:RadSliderItem Text="0" Value="0" /> 
            <telerik:RadSliderItem Text="5" Value="5" /> 
            <telerik:RadSliderItem Text="10" Value="10" /> 
        </Items> 
    </telerik:RadSlider> 
    <asp:Button ID="Button1" runat="server" Text="SetValueTo_'5'" OnClick="Button1_Click" /> 

    code-behind:
    protected void Button1_Click(object sender, EventArgs e) 
        string selectedValue = "5"
        for (int i = 0; i < RadSlider1.Items.Count; i++) 
        { 
            RadSliderItem item = RadSlider1.Items[i]; 
            if (item.Value == selectedValue) 
            { 
                RadSlider1.Value = item.Index; break;
            } 
        } 

    In case this does not help you, please open a new support ticket and send us a simple running project, demonstrating your setup, together with detailed information what you are trying to achieve.

    Kind regards,
    Tsvetie
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017