我有一个 checkbox 的问题。举个例子,我有这段 aspx 代码:
<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>
在服务器端,当检查chkActive时,我有两个渲染控件:
- ctl00$MainContent$chkActive
- ctl00$MainContent$txtName
- ctl00$MainContent$txtName
注: "消失" 表示未选中时,它不再出现在Request.Form 中。
我的 SaveData 函数:
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)))
{
//
}
}
}
para属性来自Request.Form,由于复选框不再存在于Request.Form中,所以我不知道该如何处理它。如果复选框被选中,则此函数运行良好。