Reputation: 721
I want to make a checkBox that is both
Checked = true
and
Enabled = false
How can I do this?
I wrote this code, but it removes Checked
from the checkBox
chkDecreaseAbsenceFromExtraWork.Enabled = !SecurityManager.HasAccess(Session, AccessCode.EditDecreaseAbsenceFromExtraWorkIsImpossible);
Upvotes: 1
Views: 808
Reputation: 35514
If you have a CheckBox Control
<asp:CheckBox ID="CheckBox1" runat="server" />
You set it to checked and disabled
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
CheckBox1.Enabled = false;
CheckBox1.Checked = true;
}
}
Eugene Podskal is right in that the values are not submitted. However ViewState will still set the CheckBox to checked after a PostBack.
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "CheckBox is " + CheckBox1.Checked;
}
Upvotes: 2
Reputation: 10401
Unfortunately, it seems to be by design feature of the HTML itself - values of disabled inputs will not be submitted?
You can try
Upvotes: 1