选中 CheckBox 时在 UpdatePanel 内发生回发

发布于 2024-12-05 09:37:43 字数 4141 浏览 1 评论 0原文

我有一个 ListView ,里面有一个 CheckBox ,其中 AutoPostBack 设置为 true,我还有一个可折叠面板保存在与此 CheckBox 相邻的同一个 ListView 内。

整个内容都保存在 UpdatePanel 中以进行静默回发。现在我的问题是,即使它保存在 UpdatePanel 中,当我单击 CheckBox 时,整个页面都会刷新。我需要使用静默回发来完成此操作。我怎样才能实现这个目标?

<asp:ListView ID="ListViewGroups" runat="server" 
        onitemdatabound="ListView1_ItemDataBound">


    <EmptyDataTemplate>
        <table runat="server" style="">
            <tr>
                <td>
                    No data was returned.</td>
            </tr>
        </table>
    </EmptyDataTemplate>

    <ItemTemplate>
        <tr style="">
            <td>
            <asp:Panel ID="PanelContainer" runat="server" Width="400px">

                <asp:Panel ID="PanelHeaderList" runat="server" Width="20px">
                <div style="float:left;" >
                <asp:ImageButton ID="Image1" runat="server" 
                                 ImageUrl="~/expand_blue.jpg" 
                                 AlternateText="(Show Details...)"/>
                </div>
                 </asp:Panel>
                <div style="float:left;" >       
                    <asp:CheckBox ID="CheckBox1" runat="server" 
                                  AutoPostBack="true" />            
                <asp:Label ID="Grp_NameLabel" runat="server" 
                           Text='<%# Eval("Grp_Name") %>' />
                <asp:HiddenField ID="hfGrpID" runat="server" 
                                 Value='<%#Eval("Grp_ID") %>' />
                </div>
              <br />
                <p>
                <asp:Panel ID="PanelGroupsItem" runat="server" 
                           Width="100px" >
                <asp:Panel ID="MyGroups" runat="server" 
                           ScrollBars="Vertical" 
                           Height="200px" 
                           Width="300px" 
                           Visible='<%# GetFlag(Convert.ToInt32(Eval("Grp_ID"))) %>'>

                   //Another Normal gridView here just showing some data


                   </asp:Panel>
                </asp:Panel>

                <asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1"
                                  runat="server"
                                  Collapsed="true"
                                  TargetControlID="PanelGroupsItem"
                                  CollapseControlID="PanelHeaderList"
                                  ExpandControlID="PanelHeaderList"
                                  ImageControlID="Image1"
                                  ExpandedImage="~/collapse_blue.jpg"
                                  CollapsedImage="~/expand_blue.jpg"
                                  SuppressPostBack="true"
                >
                </asp:CollapsiblePanelExtender>
                </asp:Panel>
                </p>
            </td>

        </tr>
    </ItemTemplate>
    <LayoutTemplate>
        <table runat="server">
            <tr runat="server">
                <td runat="server">
                    <table ID="itemPlaceholderContainer" runat="server" 
                           border="0" style="">
                        <tr runat="server" style="">
                            <th runat="server">
                                Groups</th>

                        </tr>
                        <tr ID="itemPlaceholder" runat="server">
                        </tr>
                    </table>
                </td>
            </tr>
            <tr runat="server">
                <td runat="server" style="">
                </td>
            </tr>
        </table>
    </LayoutTemplate>

</asp:ListView>

请帮我解决这个问题

I have a ListView and inside it I'm having a CheckBox for which AutoPostBack is set to true, I also have a Collapsible panel kept inside the same ListView adjacent to this CheckBox.

The entire thing is kept inside an UpdatePanel for Silent Post back. Now my problem is even though it is kept inside a UpdatePanel when I click on the CheckBox the Entire page is getting Refreshed. I need to do it using a Silent PostBack. How can i Achieve this??

<asp:ListView ID="ListViewGroups" runat="server" 
        onitemdatabound="ListView1_ItemDataBound">


    <EmptyDataTemplate>
        <table runat="server" style="">
            <tr>
                <td>
                    No data was returned.</td>
            </tr>
        </table>
    </EmptyDataTemplate>

    <ItemTemplate>
        <tr style="">
            <td>
            <asp:Panel ID="PanelContainer" runat="server" Width="400px">

                <asp:Panel ID="PanelHeaderList" runat="server" Width="20px">
                <div style="float:left;" >
                <asp:ImageButton ID="Image1" runat="server" 
                                 ImageUrl="~/expand_blue.jpg" 
                                 AlternateText="(Show Details...)"/>
                </div>
                 </asp:Panel>
                <div style="float:left;" >       
                    <asp:CheckBox ID="CheckBox1" runat="server" 
                                  AutoPostBack="true" />            
                <asp:Label ID="Grp_NameLabel" runat="server" 
                           Text='<%# Eval("Grp_Name") %>' />
                <asp:HiddenField ID="hfGrpID" runat="server" 
                                 Value='<%#Eval("Grp_ID") %>' />
                </div>
              <br />
                <p>
                <asp:Panel ID="PanelGroupsItem" runat="server" 
                           Width="100px" >
                <asp:Panel ID="MyGroups" runat="server" 
                           ScrollBars="Vertical" 
                           Height="200px" 
                           Width="300px" 
                           Visible='<%# GetFlag(Convert.ToInt32(Eval("Grp_ID"))) %>'>

                   //Another Normal gridView here just showing some data


                   </asp:Panel>
                </asp:Panel>

                <asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1"
                                  runat="server"
                                  Collapsed="true"
                                  TargetControlID="PanelGroupsItem"
                                  CollapseControlID="PanelHeaderList"
                                  ExpandControlID="PanelHeaderList"
                                  ImageControlID="Image1"
                                  ExpandedImage="~/collapse_blue.jpg"
                                  CollapsedImage="~/expand_blue.jpg"
                                  SuppressPostBack="true"
                >
                </asp:CollapsiblePanelExtender>
                </asp:Panel>
                </p>
            </td>

        </tr>
    </ItemTemplate>
    <LayoutTemplate>
        <table runat="server">
            <tr runat="server">
                <td runat="server">
                    <table ID="itemPlaceholderContainer" runat="server" 
                           border="0" style="">
                        <tr runat="server" style="">
                            <th runat="server">
                                Groups</th>

                        </tr>
                        <tr ID="itemPlaceholder" runat="server">
                        </tr>
                    </table>
                </td>
            </tr>
            <tr runat="server">
                <td runat="server" style="">
                </td>
            </tr>
        </table>
    </LayoutTemplate>

</asp:ListView>

Please help me on this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美煞众生 2024-12-12 09:37:43

我在这里找到了类似问题的解决方案: 当选中某个项目时,UpdatePanel 内的复选框列表会触发完整回发

您需要将复选框的ClientID模式设置为AutoID。

I found the solution for a similar issue here: Checkboxlist inside UpdatePanel triggers full postback when an item is checked.

You need to set the ClientID mode of the checkBox to AutoID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文