使用Jquery Slider时出错?

时间:2012-02-29 10:02:53

标签: jquery asp.net jquery-ui jquery-ui-slider

在附加母版页的aspx页面中使用jquery滑块时出现错误,如

 The state information is invalid for this page and might be corrupted.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The state information is invalid for this page and might be corrupted.

我的代码是

<div class="demo">
    <input type="text" class="sliderValue"  />
        <p>
        </p>
        <div id="slider"></div>
    </div>

<script language="javascript">
        $("#slider").slider({
            range: "min",
            value: 1,
            step: 10,
            min: 0,
            max: 1000,
            slide: function (event, ui) {
                $("input").val(ui.value);
            }
        });


        $("input.sliderValue").change(function (event) {
            var value1 = parseFloat($("input").val());
            var highVal = value1 * 2;
            $("#slider").slider("option", { "max": highVal, "value": value1 });
        });
    </script>

有什么建议吗?

编辑: 但是这段代码在另一个aspx页面上运行正常。我知道这个原因背后的原因

  <div>
  <input type="text" class="sliderValue" data-index="0" value="10" runat="server" />
  <input type="text" class="sliderValue" data-index="1" value="90" runat="server" />
  </div>
  <br />
  <div id="slider">
  </div>

<script language="javascript">
        $(document).ready(function () {
            $("#slider").slider({
                min: 0,
                max: 100,
                step: 1,
                range: true,
                values: [10, 90],
                slide: function (event, ui) {
                    for (var i = 0; i < ui.values.length; ++i) {
                        $("input.sliderValue[data-index=" + i + "]").val(ui.values[i]);
                    }
                }
            });

            $("input.sliderValue").change(function () {
                var $this = $(this);
                $("#slider").slider("values", $this.data("index"), $this.val());
            });
        });

    </script>

2 个答案:

答案 0 :(得分:0)

尝试将代码包装在$(document).ready(function(){});

<script language="javascript">

$(document).ready(function(){

        $("#slider").slider({
            range: "min",
            value: 1,
            step: 10,
            min: 0,
            max: 1000,
            slide: function (event, ui) {
                $("input").val(ui.value);
            }
        });


        $("input.sliderValue").change(function (event) {
            var value1 = parseFloat($("input").val());
            var highVal = value1 * 2;
            $("#slider").slider("option", { "max": highVal, "value": value1 });
        });

});
    </script>

答案 1 :(得分:0)

使用这个,我希望这会对你有所帮助

  
      
  1. 在生成错误的文件顶部添加“Debug = true”指令。例如:
  2.   
 <%@ Page Language="C#" Debug="true" %>
  

或:

     

2)将以下部分添加到您的配置文件中   应用程序:

<configuration>    <system.web>
     <compilation debug="true"/>    </system.web> </configuration>

我已经使用了您的代码并且没有像您所说的那样得到任何错误。

enter image description here