Geeks With Blogs
Frank Wang's inspirations on .NET
IEnumerable<Inspiration> inspirations = from i in DataContext.Inspirations where i.Sharable == true select i

Nobody has a doubt that the SliderExtender from the AJAX Control Toolkit is nifty. Automatic persistence of values during partial or full page postbacks, the flexibility of customizing the look and feel using CSS, and all the other good features have made the SliderExtender an ideal choice for web developers who are looking for silder controls. I did find something tricky with the SliderExtender, though, that can become annoying. For a second there, I almost considered choosing another silder control.

So how do you set the current value of the SliderExtender on the server side?  The official AJAX Control Toolkit web site mentioned the "Value" property. But guess what? The "Value" property does not even exist!!! Oh well, but still I found the solution for this after trying a few other ways that didn't work out.  Essentially, the Slider extender upgrades an asp:TextBox to a graphical slider. That's why the TargetControlID property of the SliderExtender must be specified. The Slider's value can be dynamically displayed in another asp:TextBox or an asp:Label. In this case a TextBox is used, the Slider's value can be updated through the bound asp:TextBox by calling the the DataBind method of the Slider. Let's define a slider extender in the page and point it to a TextBox that will be extended.

     <asp:TextBox ID="tbSilderValue" runat="server"/>
     <cc1:SliderExtender ID="seSliderValues" runat="server" 
                   Minimum="0" Maximum="100"  

Now suppose you have retrieved the slider value persisted in the database and you need to bind it to the slider when your page loads. Because there's no way to set the current value of the slider directly, we need to assign Text property of the asp:TextBox, which is the target control of the SliderExtender, and then call DataBind to update the slider.

protected void Page_Load(object sender, EventArgs e) 
     if (!Page.IsPostBack)
          int sliderValue = 0;
          // Get the actual value of sliderValue from database
          tbSliderValue.Text = sliderValue.ToString();
Posted on Friday, April 18, 2008 6:45 PM ASP.NET AJAX , AJAX Control Toolkit | Back to top

Comments on this post: The tricky Slider extender

# re: The tricky Slider extender
Requesting Gravatar...
Frank, could you provide your articles online demo or source code for some your posts like that or like this
because sometimes haven't time to reproduction
Left by Alexey Kucherenko on Apr 19, 2008 10:04 AM

# re: The tricky Slider extender
Requesting Gravatar...
You are over-complicating the problem... just bind the text property of the target control.
Left by mattipton on Jul 09, 2008 2:16 PM

# re: The tricky Slider extender
Requesting Gravatar...
Left by vidhya on Jun 12, 2009 1:44 AM

# re: The tricky Slider extender
Requesting Gravatar...

I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of Ajax Toolkit SliderExtender Control in ASP.Net and it helped me a lot. Thanks for sharing with us. Check out this helpful link too its also having nice post with wonderful explanation on Ajax Toolkit SliderExtender Control in ASP.Net....

Thank you very much!
Left by Ajay Singh on Jan 04, 2012 2:46 AM

# re: The tricky Slider extender
Requesting Gravatar...
Super.. Thks a lot..
Left by Kirivarnan on Nov 06, 2012 12:33 AM

Your comment:
 (will show your gravatar)

Copyright © Frank Wang | Powered by: