locked
dynamically set slider min and max values RRS feed

  • Question

  • User348142989 posted

    Hi

    I have a SQL query which will return the first and last years providing me a range.  

    If I set the associated text box to the first year, this sets the minimum for the slider.

    I then set the slider.maximum to the last year.

    Unfortunately, the slider will not respond to input by the user.  Here is my code:

    (FirstDate and LastDate are years formatted as a string and are found when I search the data base.  

    The example I am working with FirstYear = "1600" and LastYear = "1615")

    'now display range on slider as years
    sliderStartLabel.Text = "Year " & FirstDate & " to "
    slider_TextBox.Text = FirstDate
    slider_TextBox_SliderExtender.Minimum = FirstDate

    sliderEndLabel.Text = LastDate
    slider_TextBox_SliderExtender.Maximum = LastDate

    Any suggestions?  Thanks in advance for any help.

    Monday, January 23, 2017 12:22 AM

Answers

  • User348142989 posted

    Hi

    This is embarrassing.  

    I finally found a scrap of code else where on the page that set slider_TextBox_SliderExtender.Maximum = TotalNumber.ToString which proved to be my error.

    Removing this and the slider works as desired.

    BTW - I updated the control and associated text boxes and labels to format correctly (inside a table with one row) and reduced the SliderExtender to its minimum requirements.

    <table id="sliderTable">
    <tr id="slider">
    <td id="startNumber">
    <asp:Label ID="sliderStartLabel" runat="server"></asp:Label>
    </td>
    <td id="UpdatePanel">
    <asp:UpdatePanel ID="sliderUpdatePanel" runat="server" Visible="false">
    <ContentTemplate>
    <table id="myTable">
    <tr>
    <td><asp:TextBox ID="slider_TextBox" runat="server"></asp:TextBox></td>
    <td></td>
    </tr>
    </table>
    <cc1:SliderExtender ID="slider_TextBox_SliderExtender" runat="server"
    Length="500"
    TargetControlID="slider_TextBox"
    BoundControlID="OutputLabel" />
    </ContentTemplate>
    </asp:UpdatePanel>
    </td>
    <td id="endNumber">
    <asp:Label ID="sliderEndLabel" runat="server"></asp:Label>
    </td>
    <td id="goButton">
    <asp:Button ID="Go_Button" runat="server" Text="Go to " />
    <asp:Label ID="OutputLabel" runat="server"></asp:Label>
    </td>
    </tr>
    </table>

    Thanks for the help.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 23, 2017 2:01 PM

All replies

  • User-707554951 posted

    Hi TiredOldCat,

    dynamically set slider min and max values

    You could try to use a button. Use onclick event to change the max and min value in behind code

    Unfortunately, the slider will not respond to input by the user

    Do you add BoundControlID property to the slider ?

    BoundControlID is ID of the TextBox or Label that dynamically displays the slider's value.

    I have tested the follow codes and it worked

    In html:
         

           <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Label ID="sliderStartLabel" runat="server"></asp:Label>
                <asp:Label ID="sliderEndLabel" runat="server"></asp:Label>
                <asp:TextBox ID="slider_TextBox" runat="server"></asp:TextBox>
                <ajaxToolkit:SliderExtender ID="slider_TextBox_SliderExtender" runat="server"
                    TargetControlID="TextBox1"
                    BoundControlID="slider_TextBox"
                    />
    <asp:Button ID="button" runat="server" OnClick="button_Click" Text="Change min and max values" />

    In behind code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim FirstDate As String = "1600"
            Dim LastDate As String = "1615"
            sliderStartLabel.Text = "Year " & FirstDate & " to "
            slider_TextBox.Text = FirstDate
            slider_TextBox_SliderExtender.Minimum = FirstDate
            sliderEndLabel.Text = LastDate
            slider_TextBox_SliderExtender.Maximum = LastDate
        End Sub
        Protected Sub button_Click(sender As Object, e As EventArgs)
            Dim FirstDate As String = "1700"
            Dim LastDate As String = "1800"
            sliderStartLabel.Text = "Year " & FirstDate & " to "
            slider_TextBox.Text = FirstDate
            slider_TextBox_SliderExtender.Minimum = FirstDate
            sliderEndLabel.Text = LastDate
            slider_TextBox_SliderExtender.Maximum = LastDate
        End Sub

    You can refer to below link for a tutorial of SliderExtender:

    http://www.ajaxcontroltoolkit.com/Slider/Slider.aspx

    Best Regards

    Cathy

    Monday, January 23, 2017 7:18 AM
  • User348142989 posted

    Hi

    This is embarrassing.  

    I finally found a scrap of code else where on the page that set slider_TextBox_SliderExtender.Maximum = TotalNumber.ToString which proved to be my error.

    Removing this and the slider works as desired.

    BTW - I updated the control and associated text boxes and labels to format correctly (inside a table with one row) and reduced the SliderExtender to its minimum requirements.

    <table id="sliderTable">
    <tr id="slider">
    <td id="startNumber">
    <asp:Label ID="sliderStartLabel" runat="server"></asp:Label>
    </td>
    <td id="UpdatePanel">
    <asp:UpdatePanel ID="sliderUpdatePanel" runat="server" Visible="false">
    <ContentTemplate>
    <table id="myTable">
    <tr>
    <td><asp:TextBox ID="slider_TextBox" runat="server"></asp:TextBox></td>
    <td></td>
    </tr>
    </table>
    <cc1:SliderExtender ID="slider_TextBox_SliderExtender" runat="server"
    Length="500"
    TargetControlID="slider_TextBox"
    BoundControlID="OutputLabel" />
    </ContentTemplate>
    </asp:UpdatePanel>
    </td>
    <td id="endNumber">
    <asp:Label ID="sliderEndLabel" runat="server"></asp:Label>
    </td>
    <td id="goButton">
    <asp:Button ID="Go_Button" runat="server" Text="Go to " />
    <asp:Label ID="OutputLabel" runat="server"></asp:Label>
    </td>
    </tr>
    </table>

    Thanks for the help.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 23, 2017 2:01 PM