Input CheckBox Checked Property

INPUT checkbox checked property is kind of funny. This is because the name of the property also becomes the value of the property as shown in the example below:

input type="checkbox" checked = "checked"

or simply

input type="checkbox" checked

So, if you want to dynamically generate the checkbox at runtime and not make the checkbox checked then simply remove the checked property as shown below:

bool showChecked = true;

Literal lit = new Literal();

lit.Text = "<input type=\"checkbox\" " + (showChecked == true ? "Checked" : String.Empty) +"/>" ;

this.pn1.Controls.Add(lit);

this.pn1.DataBind();

In my opinion the checked property should have boolean value. So, we can say something like the following:

<input type=checkbox checked = true/false />

:)

Print | posted @ Saturday, October 27, 2007 3:22 AM

Twitter