How to set Slider control Value from ASP.NET AJAX Control Toolkit with JavaScript function?

回眸只為那壹抹淺笑 提交于 2019-12-12 23:54:19

问题


How to set Slider control Value from ASP.NET AJAX Control Toolkit with JavaScript function? Is this even possible?


回答1:


Sure is! You have to set the value of asp:TextBox control that's associated with your SliderExtender to the value that you want. So for this ASP markup:

<asp:TextBox ID="sliderBox" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:SliderExtender ID="sliderBox_SliderExtender" runat="server" Enabled="True" 
    Maximum="100" Minimum="0" TargetControlID="sliderBox">
</asp:SliderExtender>
<asp:Button ID="incButton" runat="server" Text="incrementSlider" 
    onclientclick="change();" />

Which is basically:

  1. an asp:TextBox named sliderBox (for the SliderExtender to use)
  2. an asp:SliderExtender sliderBox_SliderExtender (with basically default values)
  3. an asp:Button named incButton. This has an onClientClick property that calls the change() javascript function

And here is the change() function:

<script type="text/javascript">
    function change() {
        document.getElementById("sliderBox").value += 10;
    }
</script>

The change() function increments the value in the asp:TextBox control by 10, thus increasing the sliders position each time you click the button.



来源:https://stackoverflow.com/questions/7315483/how-to-set-slider-control-value-from-asp-net-ajax-control-toolkit-with-javascrip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!