0

Here's my code:

    function display() {
        $(document).ready(function () {

            var txtStart = $("#TextBox1");
            var txtStartDate = $(txtStart).val(); //Value from arrival

            var txtEnd = $("#TextBox2");
            var txtEndDate = $(txtEnd).val();
            var minDate = new Date(txtStartDate);
            var maxDate = new Date(txtEndDate);

            $("#slider").slider({
                min: minDate.getTime(),
                max: maxDate.getTime(),
                step: 60 * 60 * 24 * 1000, // 1 day
                slide: function (e, ui) {
                    var currentDate = new Date(ui.value);
                    $('#now').text(currentDate.toDateString());
                },

                change: function (e, ui) {

              /*I want to run the code behind function here*/    

                }
            });
        });
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Welcome to SO. It is not clear what does it mean 'behind function' ? You want to run smth before change? – dganenco Sep 18 '19 at 14:44
  • code behind means a function in aspx.cs in asp.net – Paramee Kulangana Sep 18 '19 at 14:45
  • no i dont want to change something before . i want to run the aspx.cs function when the sliders' current value get changed – Paramee Kulangana Sep 18 '19 at 14:50
  • If I'm reading what aspx.cs is correctly, it's server side code. So you will not be able to call methods directly from the client. You will have to perform an ajax call. – Taplar Sep 18 '19 at 15:02
  • Possible Duplicate: https://stackoverflow.com/questions/28827196/how-to-call-a-codebehind-function-from-javascript-in-asp-net – Twisty Sep 18 '19 at 15:02

1 Answers1

0

To execute the "code behind" or your Server Side script, you must Post back via AJAX. In your Change Callback, you will want to do something like:

change: function(e, ui){
  $.ajax({
    type: "POST",
    url: "~/code_behind.aspx/Method",
    data: { date: $('#now').val() },
    contentType: "application/json; charset=utf-8"
  });
}

Since it's not clear from your post, I cannot clarify further. You will need to adapt this to your scripts and your needs.

Twisty
  • 30,304
  • 2
  • 26
  • 45