"
ASP.NET (snapshot 2017) Microsoft documentation and samples

Databinding the Slider Control (C#)

by Christian Wenz

Download Code or Download PDF

The Slider control in the AJAX Control Toolkit provides a graphical slider that can be controlled using the mouse. It is possible to bind the current position of the slider to another ASP.NET control.

Overview

The Slider control in the AJAX Control Toolkit provides a graphical slider that can be controlled using the mouse. It is possible to bind the current position of the slider to another ASP.NET control.

Steps

In order to activate the functionality of ASP.NET AJAX and the Control Toolkit, the ScriptManager control must be put anywhere on the page (but within the <form> element):

[!code-aspxMain]

   1:  <asp:ScriptManager ID="asm" runat="server" />

Next, add two TextBox controls to the page. One will be transformed into a graphical slider, and the other one will hold the position of the slider.

[!code-aspxMain]

   1:  <asp:TextBox ID="Slider1" runat="server" />
   2:  <asp:TextBox ID="SliderValue" runat="server" />

The next step is already the final step. The SliderExtender control from the ASP.NET AJAX Control Toolkit makes a slider out of the first text box and automatically updates the second text box when the slider position changes. In order for that to work, The SliderExtender’s TargetControlID attribute must be set to the ID of the first text box; the BoundControlID attribute must be set to the ID of the second text box.

[!code-aspxMain]

   1:  <ajaxToolkit:SliderExtender ID="se1" runat="server" TargetControlID="Slider1"
   2:   BoundControlID="SliderValue" />

As you can see in the browser, the data binding works in both directions: entering a new value in the text box updates the slider’s position. If you make the second text box read only, you may add a weak protection to the text field so that it is harder for the user to manually update the value in there.

Slider and text box are in sync

Slider and text box are in sync (Click to view full-size image)

Previous Next



Comments ( )
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnet/web-forms/overview/ajax-control-toolkit/slider/databinding-the-slider-control-cs.htm
< THANKS ME>