Gridview TemplateField checkbox postback behavior in asp.net

3.1k Views Asked by At

I have GridView inside UpdatePanel and UpdateMode of the UpdatePanel is set to conditional.

Gridview contains asp:CheckBox as TemplateField and rest of the columns are boundfields which are dynamically created. Checbox AutoPostBack is set to true and I update a datatable (which is inside session) based on checkbox value.

Here is markup:

<asp:GridView ID="ObjList" runat="server"  CssClass="ObjList" AutoGenerateColumns="false" OnRowDataBound="ObjList_RowDataBound" AutoGenerateSelectButton="false" AllowPaging="False">
    <Columns>
        <asp:TemplateField HeaderText="&nbsp">
            <HeaderTemplate>
                <asp:CheckBox AutoPostBack="true" ID="chkAll" runat="server" OnCheckedChanged="HeaderChk_Changed" />
                <asp:HiddenField ID="LinkNumIndexHead" runat="server" Value="-1" />
            </HeaderTemplate>
        <ItemTemplate>
            <asp:CheckBox AutoPostBack="true" ID="chkRow" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Selection")%>'
                    OnCheckedChanged="ChkRow_OnCheckChange" />                                                 
        </ItemTemplate>                                                
        </asp:TemplateField>
    </Columns>
 </asp:GridView>

In Deployed version only: Whenever user click 2 or more checkboxes in fast speed. Postback of first checkbox fires and rest of checkboxes get unchecked. How can I control this behavior?

When Local IIS is running: Postback of every checkbox fires.

In Firebug debugging it is noticed that Postback of first checkbox takes quite a time. Please tell me how can I avoid this situation.

1

There are 1 best solutions below

1
On

Try this

<asp:GridView ID="ObjList" runat="server" CssClass="ObjList" AutoGenerateColumns="false"
    OnRowDataBound="ObjList_RowDataBound" AutoGenerateSelectButton="false" AllowPaging="False">
    <Columns>
        <asp:TemplateField HeaderText="&nbsp">
            <HeaderTemplate>
                <asp:UpdatePanel runat="server">
                    <ContentTemplate>
                        <asp:CheckBox AutoPostBack="true" ID="chkAll" runat="server" OnCheckedChanged="HeaderChk_Changed" />
                    </ContentTemplate>
                </asp:UpdatePanel>
                <asp:HiddenField ID="LinkNumIndexHead" runat="server" Value="-1" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                    <ContentTemplate>
                        <asp:CheckBox AutoPostBack="true" ID="chkRow" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Selection")%>'
                            OnCheckedChanged="ChkRow_OnCheckChange" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>