0

I have this grid set up.... it all works totally fine... except one issue...

<asp:GridView runat="server" 
     ID="grdFacetsAssigned" 
     AllowPaging="false" 
     AllowSorting="True" 
     DataKeyNames="lngSystemFacet" 
     OnSelectedIndexChanging="grdFacetsAssigned_SelectedIndexChanging"
         CssClass="table_scroll" 
         AutoGenerateColumns="False" GridLines="None" 
         ShowHeader="false" Width="500px" 
         OnSelectedIndexChanged="grdFacetsAssigned_SelectedIndexChanged"
         ShowFooter="false" PagerSettings-Visible="false" 
         DataSourceID="SM_spStateUpdateReport_FacetAssignList" 
         OnRowCreated="grdFacetsAssigned_RowCreated">
         <RowStyle CssClass="table_row" />
         <Columns>
             <asp:TemplateField Visible="false">
                 <ItemTemplate>
                     <asp:Label ID="lbllngSystemFacetID" runat="server" 
                     Text='<%# Eval("lngSystemFacetID") %>' />
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:BoundField DataField="strSystemSystemFacet" SortExpression="strSystemSystemFacet" 
             ItemStyle-Width="50%" />
             <asp:TemplateField ItemStyle-Width="30%" ItemStyle-HorizontalAlign="Center" 
             SortExpression="bolAssigned">
                 <ItemTemplate>
                     <asp:CheckBox ID="chkFacetAssigned" runat="server" 
                     OnClientClick="alert(this.checked);" 
                     OnCheckedChanged="chkFacetAssigned_CheckedChanged"
                         AutoPostBack="True" Checked='<%# Eval("bolAssigned") %>' />
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField SortExpression="intOrder" 
             HeaderText="Display Order" ItemStyle-Width="20%">
                 <ItemTemplate>
                     <asp:Label ID="lblAssignedFacetOrder" runat="server" 
                     Text='<%#DataBinder.Eval(Container.DataItem, "intOrder")%>'></asp:Label>
                     <asp:TextBox ID="txtAssignedFacetOrder" runat="server" 
                     CssClass="gridview_input" 
                     Text='<%#DataBinder.Eval(Container.DataItem, "intOrder")%>' 
                     Visible="False"></asp:TextBox>
                 </ItemTemplate>
             </asp:TemplateField>
         </Columns>
         <SelectedRowStyle CssClass="table_selected_row" />
         <AlternatingRowStyle CssClass="table_alternating_row" />
         <EmptyDataRowStyle CssClass="table_empty" />
         <EmptyDataTemplate>
             No Data
         </EmptyDataTemplate>
     </asp:GridView>

When you click the chkFacetAssigned checkbox the appropriate event fires. The code works well from there. What happens though is when the checkbox is checked... if the row is not selected there are two postbacks that happen. The first postback is from the grid and the second postback is from the checkbox. Both postbacks cause the chkFacetAssigned_CheckedChanged event to be called- resulting in code running twice that should only run once. I should note that if the row is already selected (the row the checkbox is on) you do not see this extra postback. Someone please help.

There are no other event handlers registered or anything like this.

1
  • Could you put some more spaces before your code? I can still read some of it Commented Aug 22, 2013 at 20:57

2 Answers 2

1

First line of your code. Remove the following.

OnSelectedIndexChanging="grdFacetsAssigned_SelectedIndexChanging"

Second Line

OnSelectedIndexChanged="grdFacetsAssigned_SelectedIndexChanged"
Sign up to request clarification or add additional context in comments.

1 Comment

I use those events for other purposes. What I don't understand is why the checkbox event fires twice when it may be these events that fire. Then it posts-back again. I see where you are going but I need to handle those events as well.
0

What I did for this was a workaround in the checkbox event handler...

            if (Page.Request.Params["__EVENTTARGET"].IndexOf("chkFacetAssigned") < 1)
        {
            return;
        }

This ensures that the event is ignored unless it is responding to a postback that was initiated by the checkbox and not the grid.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.