Properties
The ToggleState property is responsible for getting or setting the state of RadToggleButton.
Events
You can handle the ToggleStateChanged event of RadToggleButton
to take action when the user toggles the button. The event handler is passed a
StateChangedEventArgs parameter that includes a ToggleState
member.
Copy[C#] Handling the ToggleStateChanged event
void radToggleButton1_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
MessageBox.Show(args.ToggleState.ToString());
}
Copy[VB.NET] Handling the ToggleStateChanged event
Private Sub radToggleButton1_ToggleStateChanged(ByVal sender As Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs)
MessageBox.Show(args.ToggleState.ToString())
End SubYou can also handle the ToggleStateChanging event. This event
provides an opportunity to cancel the toggle state change. The StateChangingEventArgs
passed as a parameter to the event handler have NewValue and
OldValueToggleState members and a
Boolean Cancel member. NewValue holds
the value of ToggleState that will be applied when the event is
completed without being canceled. OldValue holds the value of
ToggleState at the time the state change was initiated.
Cancel controls which value of ToggleState is
applied when the event completes. The default is false.
Setting Canceled to true will prevent
ToggleStateChanged from firing and will leave the
ToggleState value as it was prior to the event.
The example below allows a RadToggleButton to toggle only
when a second RadToggleButton is off. If the second button toggle
state is On and the NewValue is On,
then the toggle is canceled. The ToggleStateChanged event only fires
and changes the Text property when ToggleStateChangiing
does not cancel.
Copy[C#] Handling the ToggleStateChanging event
private void radToggleButton2_ToggleStateChanging(object sender,
Telerik.WinControls.UI.StateChangingEventArgs args)
{
bool attemptingOn = args.NewValue ==
Telerik.WinControls.Enumerations.ToggleState.On;
args.Cancel = true;
}
private void radToggleButton2_ToggleStateChanged(object sender,
Telerik.WinControls.UI.StateChangedEventArgs args)
{
radToggleButton1.Text = args.ToggleState.ToString();
}
Copy[VB.NET] Handling the ToggleStateChanging event
Private Sub radToggleButton2_ToggleStateChanging(ByVal sender As Object, ByVal args As Telerik.WinControls.UI.StateChangingEventArgs)
args.Cancel = True
End Sub
Private Sub radToggleButton2_ToggleStateChanged(ByVal sender As Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs)
radToggleButton1.Text = args.ToggleState.ToString()
End Sub