Search code examples
c#jqueryasp.netjquery-slider

How do I access a variable from my markup page?


This is going to sound pretty basic but I have to ask anyways.I have a jQuery range slider, I have labels that show what step the slider handle is at. So I added this variable

var myData = $("slider-range").slider("option", "min");

In my codebehind page I'm trying to access that variable and I can't figure it out.

The code for the slider is,

$(function () {

    $("#slider-range-Monday").slider({

        create: function (e, ui) {
            var c = $(this).children('.ui-slider-handle')
            $(c[0]).append('<a class="ui-slider-label">0</a>');
            $(c[1]).append('<a class="ui-slider-label">24</a>');
        },

              range: true,

              min: 0,

              max: 24,

              values: [0, 24],

              animate: 'slow',



              slide: function (event, ui) {
                  $('.ui-slider-label', this)[0].innerHTML = ui.values[0];
                  $('.ui-slider-label', this)[1].innerHTML = ui.values[1];

                  $("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);

              }

          });

          $("#amount").val("$" + $("#slider-range").slider("values", 0) +

            " - $" + $("#slider-range").slider("values", 1));

          var myData = $("slider-range").slider("option", "min");

});

I need to be able to access the sliders values and I don't know how. I thought about adding a hidden label to the sliders labels and I don't know how to do that later. If this has been asked before please point me in the right direction.

Thanks


Solution

  • You can add a hidden field

       <asp:HiddenField ID="hiddenField" runat="server" />
    

    Set its value like

    $(document).ready(function() {
        $("#<%=hiddenField.ClientID%>").val(myData )
    });