asp.net ajax控件工具包滑块

时间:2012-04-11 08:06:38

标签: asp.net asp.net-ajax ajaxcontroltoolkit

我使用ajax controltoolkit滑块我想将滑块限制在一定范围内。

Fr ex:我的滑块最小值为0& maxvalue是10000,但我只能滚动到7000, 我的滑块必须从0移动到7000,但范围栏必须为10000。 有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

有一个名为OnClientDrag的滑块事件,您可以做的是创建一个jquery / javascript函数,它将在更改时检查值,当它达到7000时,您可以通过jquery方法取消该事件,类似这样的事情可能求助:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:TextBox ID="Slider1" runat="server" AutoPostBack="false" style="right:0px" Text="0"/>
        <ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server"
            BehaviorID="Slider1"
            TargetControlID="Slider1"
            Minimum="-100"
            Maximum="100"
            BoundControlID="Slider1_BoundControl"
            Steps="5" />

        <input id="btnDisable" type="button" value="Disable" onclick="disableSlider()"/>
        <input id="btnEnable" type="button" value="Enable" onclick="enableSlider()" disabled="true"/>
        <script type="text/javascript" language="javascript">
            function disableSlider(){
                 $clearHandlers($find('Slider1')._handle);
                 $clearHandlers($find('Slider1')._railElement);
                 $get('btnDisable').disabled = true;
                 $get('btnEnable').disabled = false;
            }
            function enableSlider(){
                 $addHandlers($find('Slider1')._handle, 
                    {
                        'mousedown': $find('Slider1')._onMouseDown,
                        'dragstart': $find('Slider1')._IEDragDropHandler,
                        'drag': $find('Slider1')._IEDragDropHandler,
                        'dragend': $find('Slider1')._IEDragDropHandler
                    },
                    $find('Slider1'));

                $addHandlers($find('Slider1')._railElement,
                    {
                        'click': $find('Slider1')._onRailClick
                    },
                    $find('Slider1'));
                $get('btnDisable').disabled = false;
                $get('btnEnable').disabled = true;
            }
        </script>
    </form>
</body>
</html>