I have a problem with checkbox. For example, I have this aspx's code
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:CheckBox ID="chkActive" AutoPostBack="True" OnCheckedChanged="Active_OnCheckedChanged" runat="server"></asp:CheckBox>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</asp:Content>
At server side, when chkActive is checked, I have two rendered controls:
- ctl00$MainContent$chkActive
- ctl00$MainContent$txtName
when chkActive is unchecked, I have only one rendered control:
- ctl00$MainContent$txtName
So I cannot write the status of that checkbox to database. For the record, I use a SaveData function with dynamic object, and chkActive disappeared when unchecked, so this function couldn't find it. Any idea to make checkbox appeared even when it's unchecked? Thanks.
P.S: "disappeared" means it's not in Request.Form anymore when unchecked.
Edited:
My SaveData function:
public void SaveDate<T>(T entity, NameValueCollection attributes)
{
PropertyInfo[] properties = typeof(T).GetProperties();
foreach (PropertyInfo property in properties)
{
if (attributes.AllKeys.Any(key => key.Contains("$" + property.Name)))
{
//
}
}
}
The para attributes is from Request.Form, since checkbox is not in Request.Form anymore, so I don't know how to handle it. This function works well in case checkbox is checked