$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
How to Build Toggle Button using C#
Home > How to > Toggle Button
A toggle button is a specicalized button which can be selected. Thus, it can be counted as a button control that allows user to change a setting between two states. And the PerButton control can not only allow users to create a toggle button in ASP.NET web application using C#.NET programming code but also enable users to customize the appearance styling of created toggle button. And now the PerButton control has been used in the ASP.NET web projects which need many checkbox buttons or radio buttons or other customized toggle buttons.
From this article, you will find detailed Visual C# .NET programming codes for building and creating a fully customized toggle button in asp.net web application. Before following the sample programming guidance listed below, please make sure that your ASP.NET web application has installed NET Framework 3.5 or above versions and that you have installed all the necessary dlls from our ASP.NET AJAX SDK into your ASP.NET web application.

Set Button Type Using C# Code

The PerButton offers several options for the Button Type properties, including ToggleButton, StandardButton, LinkButton and SkinnedButton. Here you need to set the button type to ToggleButton.
btnSeason.ButtonType = PerButtonType.ToggleButton;

Define Toggle Type Using C# Code

To make sure that users can create a toggle button whose appearance is fully tailored at their requests, the PerButton control also provides three available options for the Toggle Type property, which are CheckBox, Radio and CustomToggle.
btnSeason.ToggleType = ButtonToggleType.CustomToggle;

Customize the Button Size Using C# Code

The width & height of the toggle button can be accurately defined using following C# code.
btnSeason.Width = 100;
btnSeason.Height = 60;

Set the Toggle State Using C# Code

The property ToggleState is responsible for the button state after it is clicked. In following C# code, we add 4 states to the toggle button. The initial value of the ToggleState property is spring. After the first click, the background image of the button will be changed to summer and the text on the button will be changed at the same time. After the second click, the background image of the button and the text on the button will change to the autumn. With the third click, the background image of the button and the text on the button will be changed to winter. And when the background image of button becomes the winter, one click on the button will make the button return to the initial value of spring.
PerButtonToggleState toggleState1 = newPerButtonToggleState();
toggleState1.ImageUrl = "../../../../Images/Button/Spring.jpg";
toggleState1.Text = "Spring";
toggleState1.IsBackgroundImage = true;
toggleState1.Selected = true;
btnSeason.ToggleStates.Add(toggleState1);

PerButtonToggleState toggleState2 = newPerButtonToggleState();
toggleState2.ImageUrl = "../../../../Images/Button/Summer.jpg";
toggleState2.Text = "Summer";
toggleState2.IsBackgroundImage = true;
btnSeason.ToggleStates.Add(toggleState2);

PerButtonToggleState toggleState3 = newPerButtonToggleState();
toggleState3.ImageUrl = "../../../../Images/Button/Autumn.jpg";
toggleState3.Text = "Autumn";
toggleState3.IsBackgroundImage = true;
btnSeason.ToggleStates.Add(toggleState3);

PerButtonToggleState toggleState4 = newPerButtonToggleState();
toggleState4.ImageUrl = "../../../../Images/Button/Winter.jpg";
toggleState4.Text = "Winter";
toggleState4.IsBackgroundImage = true;
btnSeason.ToggleStates.Add(toggleState4);
ASP.NET AJAX UI Controls