Friday 28 November 2008

A RadioButton is a Checkbox

If you have this code and you are dealing with a RadioButton control
then the output CSS class will be HighlightedBackgroundCheckbox because
a RadioButton is a Checkbox.

Simple fix is to check its a radiobutton first.



namespace System.Web.UI.WebControls
public class RadioButton : CheckBox







foreach (string boundNameToCompare in boundNames)
{
CheckBox cb =
this.FindControl(this.TargetControlID) as CheckBox;
if (cb != null)
{
cb.CssClass = "HighlightedBackgroundCheckbox";
continue;
}

RadioButton rb =
this.FindControl(this.TargetControlID) as RadioButton;
if (rb != null)
{
rb.CssClass = "radio HighlightedBackground";
continue;
}

}

No comments: