邮箱上的复选框状态未更改

时间:2016-01-15 23:49:35

标签: c# asp.net checkbox postback

我为用户控件(.ascx)

添加了以下标记
<table>
<tr>
    <td>
        <asp:Label ID="Label1" runat="server" Text="Select Logical Symbol to Search:"></asp:Label>
    </td>
    <td>
        <asp:DropDownList ID="ddlComponentType" runat="server" 
            onselectedindexchanged="ddlComponentType_SelectedIndexChanged" AutoPostBack="true">
        </asp:DropDownList>
    </td>
    <td>
        <asp:CheckBox ID="chkAdvSearchAllLibs" runat="server" ToolTip="Check this box to search all available libraries" Text="Search All Libraries"/>
    </td>
</tr>
<tr>
    <td>
        <asp:Label ID="Label2" runat="server" Text="Search by Logical Symbol Properties:"></asp:Label>
    </td>
    <td>
    </td>
</tr>

在页面加载

protected void Page_Load(object sender, EventArgs e)
{
     SearchResults(ref attributeSearch, compTypeID);
}

其中SearchResults是

 private void SearchResults(ref string attributeSearch, int compTypeID)
    {
        DataTable dtResults = this.AdvancedSearchControl.GetSearchResults(ref attributeSearch, compTypeID);
    }

在我的UserControl.ascx.cs

public DataTable GetSearchResults(ref string _attrVals, int compTypeID)
{
                //Other Logic Goes Here
                IEnumerable<Model.ComponentInfo.ComponentType> compTypeResult = from compTypes in BLLibrary.GetComponentTypeBasedOnLib(this.CurrentLibraryId, this.CurrentLibrary, this.chkAdvSearchAllLibs.Checked) select compTypes.Value;
}
无论是否在页面上检查this.chkAdvSearchAllLibs.Checked并将其张贴回来,

check-box始终为假。

1 个答案:

答案 0 :(得分:1)

服务器端:

将AutoPostBack =“True”添加到CheckBox。它没有回发。

客户端:

<asp:CheckBox runat="server" ID="cb" onclick="checkboxchanged(this);" />

function checkboxchanged( sender ) {
if ( sender.checked ) {
        // clicked and checked
    } else {
        // clicked and unchecked
    }
}