Welcome to AspAdvice Sign in | Join | Help

Alessandro Gallo

.NET & Beyond
SliderExtender layout and custom appearance

This post helps you understanding how the slider’s layout is structured and how to change the default appearance.

Layout

The Slider Extender replaces an extended asp:TextBox control with a graphical slider, as shown in figure 1.

Figure 1. Layout of the slider

As you can see from figure 1, the slider consists of an outer div element (in red) called the rail, and an inner div element (in green) called the handle. An img element nested in the handle div is used to display the handle’s image. This results in the following DOM hierarchy:

<div>

<div>

<img />

</div>

</div>

Default appearance

By default, the slider is rendered using default CSS classes for both the rail and the handle, as shown in figure 2.

Figure 2: Default appearance

The rail’s background image and the handle’s image are embedded as web resources in the AjaxControlToolkit assembly.

  • A horizontal slider uses the .ajax__slider_h_handle and .ajax__slider_h_rail CSS classes for the handle and the rail, respectively.
  • A vertical slider uses the .ajax__slider_v_handle and .ajax__slider_v_rail CSS classes for the handle and the rail, respectively.

Overriding the default CSS classes affects all the sliders hosted in a page.

When using the default theme, the only property that can be overridden on a per-slider basis is the slider’s length. This can be done by setting the Length property on the SliderExtender to an integer value.

At present, all the values are specified in pixels.

Now, let’s see how to customize the slider’s appearance.

Custom Appearance

In order to customize the slider’s appearance, we need to:

  • Provide a CSS class for the rail
  • Provide a CSS class for the handle
  • Provide an image URL for the handle’s image.

Steps to perform:

1. Create a CSS class for the slider’s rail. The CSS class must contain the following attributes:

  • The position attribute must be set to relative.
  • Default values for height and width attributes must be provided. The width value can be overridden through the Length property of the SliderExtender.
  • To embed a background image for the rail, use the background attribute.

2. Create a CSS class for the slider’s handle. The CSS class must contain the following attributes:

  • The position attribute must be set to absolute.
  • Values for height and width attributes must be provided.

3. Provide an image for the slider’s handle. The height and width sizes of the image must be equal to the height and width values specified in the handle’s CSS class.

4. Set the RailCssClass property of the SliderExtender instance to the name of the rail CSS class.

5. Set the HandleCssClass property of the SliderExtender instance to the name of the handle CSS class.

6. Set the HandleImageUrl property of the SliderExtender instance to the URL of the handle’s image.

Figure 3 shows a customized slider.

Figure 3: Custom appearance

The slider in figure 3 has been declared as follows:

<asp:TextBox ID="Slider" runat="server"></asp:TextBox>

<ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server"

TargetControlID="Slider"

RailCssClass="slider_rail"

HandleCssClass="slider_handle"

HandleImageUrl="slider_custom_handle.png"

/>

The CSS classes for the slider’s rail and handle are defined like so:

.slider_rail {

position: relative;

height: 15px;

width: 200px;

background: #FFFFFF url(slider_custom_rail.png) repeat-x;

}

.slider_handle {

position: absolute;

height: 14px;

width: 22px;

}

Note that the default value of 200px set for the width attribute in the rail CSS class can be overridden through the Length property of the SliderExtender. As usual, the height and width attributes are swapped when dealing with vertical sliders.

Posted: Monday, December 10, 2007 5:44 PM by Garbin

Comments

TerryLee said:

概述推荐系列是我新开的一个链接系列,将会推荐精彩的英文、中文文章,主要是Web开发方面的,但不局限于Web开发,尽量保持每周推荐一次的频率,希望对大家有所帮助。本文为第01期,有12篇文章:1.C...

# December 18, 2007 8:21 AM

Jacky_Xu said:

概述

推荐系列是我新开的一个链接系列,将会推荐精彩的英文、中文文章,主要是Web开发方面的,但不局限于Web开发,尽量保持每周推荐一次的频率,希望对大家有所帮助。本文为第01期,有12篇文章:

...

# December 23, 2007 9:52 PM

曹振华 said:

推荐系列:2007年第01期总1期 概述

推荐系列是我新开的一个链接系列,将会推荐精彩的英文、中文文章,主要是Web开发方面的,但不局限于Web开发,尽量保持每周推荐一次的频率,希望对大家有...

# January 30, 2008 1:05 AM

rox19840702 said:

12月16日链接篇: ASP.NET, ASP.NET AJAX, ASP.NET MVC, VS, .NET, IIS7, WPF

# February 27, 2008 11:28 AM

santosh said:

problem using sliderextender unnecessary vertical scrol bar on IE browser

# May 6, 2008 10:28 AM

Garbin said:

Please log bugs in the Issue Tracker at CodePlex:

http://www.codeplex.com/AtlasControlToolkit/WorkItem/List.aspx

# May 6, 2008 10:41 AM

Lee said:

Hi,

I have set the same custom appearance for the slider as shown in your demo code. Everything is fine but the handler just disappears.

I cant figure out what i am missing.....

# June 18, 2008 2:28 AM

sunjie said:

推荐系列是我新开的一个链接系列,将会推荐精彩的英文、中文文章,主要是Web开发方面的,但不局限于Web开发,尽量保持每周推荐一次的频率,希望对大家有所帮助。本文为第01期,有12篇文章:

1.Cre...

# July 21, 2008 10:09 PM
New Comments to this post are disabled