简体   繁体   中英

Checkbox state not changed on postback

I have the following mark up for a User Control (.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>

On page Load

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

where SearchResults is

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

And in my 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 is always false no matter if the check-box is checked on page and posted back or not.

Server side:

Add AutoPostBack="True" to the CheckBox. It's not posting back.

Client side:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM