Atlas: Creating Better Looking Checkboxes with the ToggleButtonExtender

With the ToggleButtonExtender from the Atlas Control Toolkit, you can easily create nice looking checkboxes. The ToggleButtonExtender styles ASP.NET Checkbox controls with images. In this post, I'll show you how easy it is to create the following styled checkboxes.

You can see it in action here:

You can try it here:
http://atlas.vertigosoftware.com/AtlasToggleButton/ToggleButton.aspx

ASPX Code
The aspx code contains four ASP.NET Checkboxes and the ToggleButtonExtender. The ToggleButtonExtender contains three properties to configure the image replacement for the three corresponding checkboxes.

<atlas:ScriptManager ID="ScriptManager1" runat="server" />
<div class="togglebutton">
    <asp:CheckBox ID="CheckBox1" runat="server" Text="Default ASP.NET Checkbox" /><br /><br />
    <asp:CheckBox ID="CheckBox2" runat="server" Text="Improved Checkbox with the ToggleButtonExtender" /><br />
    <asp:CheckBox ID="CheckBox3" runat="server" Checked="true" Text="Can extend multiple checkboxes" /><br />
    <asp:CheckBox ID="CheckBox4" runat="server" Text="Any icon can be used" />
</div>
<atlastoolkit:ToggleButtonExtender ID="ToggleButtonExtender1" runat="server">
    <atlastoolkit:ToggleButtonProperties TargetControlID="CheckBox2" CheckedImageUrl="images/checked.png"
        UncheckedImageUrl="images/unchecked.png" ImageHeight="16" ImageWidth="16" />
    <atlastoolkit:ToggleButtonProperties TargetControlID="CheckBox3" CheckedImageUrl="images/checked.png"
        UncheckedImageUrl="images/unchecked.png" ImageHeight="16" ImageWidth="16" />
    <atlastoolkit:ToggleButtonProperties TargetControlID="CheckBox4" CheckedImageUrl="images/ToggleButton_Checked.gif"
        UncheckedImageUrl="images/ToggleButton_Unchecked.gif" ImageHeight="19" ImageWidth="19" />
</atlastoolkit:ToggleButtonExtender>

Design Time Support
One of the neat things about the extender model is that Visual Studio will recognize that there is a checkbox extender on the page and will expose the ToggleButtonextender's properties to any of the ASP.NET Checkboxes.

ASPX Code-Behind
There is no code-behind as no logic is necessary on the server.

Styles
Here is the corresponding styles for my toggle butons, mostly to control spacing.

<style type="text/css">
body {
font:normal 10pt/13pt Arial, Verdana, Helvetica, sans-serif;
color:#666;
margin:20px;
}
.togglebutton {
padding-top:13px;
}
.togglebutton label {
padding-left:8px;
}
</style>

Source Code

You can download the source to this demo at:

Source: http://blogs.vertigosoftware.com/files/alan/atlastogglebutton.zip

posted on Thursday, July 27, 2006 4:46 PM by AlanL

Comments

# Atlas “How Do I?” Video Series Begins

Thursday, July 27, 2006 10:53 PM by Community Blogs
Earlier this spring we published a really popular series of short, focused, online ASP.NET videos that

# Atlas “How Do I?” Video Series Begins

Thursday, July 27, 2006 11:04 PM by ATLAS Team Blogs
Earlier this spring we published a really popular series of short, focused, online ASP.NET videos that

# re: Atlas: Creating Better Looking Checkboxes with the ToggleButtonExtender

Friday, July 28, 2006 8:08 AM by Steve
What is causing the constant "flicker" when running the mouse over the graphics? (i'm using IE 6)

# re: Atlas: Creating Better Looking Checkboxes with the ToggleButtonExtender

Friday, July 28, 2006 10:44 AM by Alan Le
You're right, there is an image flicker issue with ie6 when working with css to dynamically change the image. ScottGu posted about two potential solution awhile back: http://weblogs.asp.net/scottgu/archive/2006/05/29/Eliminating-CSS-Image-Flicker-with-IE6.aspx. It's kind of out of scope of this particular example though. In future posts, I'll add a section for known issues.

# [翻译]Atlas: Creating Better Looking Checkboxes with the ToggleButtonExtender

Sunday, July 30, 2006 11:36 PM by 石涛
使用“Atlas Control Toolkit”中的“ToggleButtonExtender”,你可以创建非常酷的“checkboxes”:“ ToggleButtonExtender”使用图片 来“装扮”ASP.NET 的“Checkbox”控件 !

# Atlas: Using the DragOverlayExtender with the ASP.NET Profile Service

Monday, August 14, 2006 3:07 PM by Alan Le
My last two posts on Atlas has been well received. I plan to continue writing quick demos as I explore...

# Atlas: Using the DragOverlayExtender with the ASP.NET Profile Service

Monday, September 25, 2006 9:49 AM by Alan Le
My last two posts on Atlas has been well received. I plan to continue writing quick demos as I explore...

# re: Atlas: Creating Better Looking Checkboxes with the ToggleButtonExtender

Thursday, April 12, 2007 10:39 AM by Jenia
Is it possible to add the ToggleButtonExtender to the items within a CheckBoxList?