隐藏DIV内的ASP.NET CheckBox始终返回false

时间:2013-05-18 17:18:51

标签: javascript asp.net css vb.net webforms

我在隐藏div中有一些表单元素,如下所示:

<div id="jDivUpdateFolder" style="display:none;">
    <asp:TextBox ID="txtEditFolderName" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="txtEditFolderDesc" runat="server" TextMode="MultiLine"></asp:TextBox><br />
    <asp:FileUpload ID="fuEditPhoto" runat="server" /><br />
    <asp:DropDownList ID="ddlEditContentOrder" runat="server">
        <asp:ListItem Value="0" Text="Ascending"></asp:ListItem>
        <asp:ListItem Value="1" Text="Descending"></asp:ListItem>
    </asp:DropDownList><br />
    <asp:CheckBox ID="chkEditIsActive" runat="server" Text="Active" /><br />
    <asp:CheckBox ID="chkEditShowOnHome" runat="server" Text="Show on HomePage" /><br />
    <asp:LinkButton CssClass="anchorbutton green" ID="btnSaveEditFolder" Text="Save" runat="server"></asp:LinkButton>

我通过jQuery中的函数切换此div的可见性(为简单起见,此处不包括它)

当使用btnSaveEditFolder的click事件提交表单时,我可以正确地检索TextBoxes,FileUpload控件和DropDownList的所有值。但不知何故,复选框总是返回false。我很疯狂......

Protected Sub btnSaveEditFolder_Click(sender As Object, e As System.EventArgs) Handles btnSaveEditFolder.Click
    Dim fID As Integer = Convert.ToInt32(txtFolderID.Value.Trim) ' value is good
    Dim fname As String = txtEditFolderName.Text.Trim ' value is good
    Dim fdesc As String = txtEditFolderDesc.Text.Trim ' value is good
    Dim order As String = IIf(ddlEditContentOrder.SelectedItem.Value = "0", "Asc", "Desc") ' value is good
    Dim isactive As Boolean = IIf(chkEditIsActive.Checked, True, False) ' ## ALWAYS FALSE
    Dim isvisible As Boolean = IIf(chkEditShowOnHome.Checked, True, False) ' ## ALWAYS FALSE
End Sub

当我删除样式display:block;并且表单在页面上可见时,它们会返回正确的值(如果选中则返回true,否则返回false)。

有人遇到过这样的问题吗?

2 个答案:

答案 0 :(得分:0)

将复选框的值设置为true:

value="True"

发布并告知我是否有效。听起来很傻,但只是这样做,然后大声喊回来,如果没有,那么我会进一步为你调查。

答案 1 :(得分:0)

尝试:

Dim isactive As Boolean = chkEditIsActive.Checked