How to get the checkbox id that placed in a repeater for update panel?

被刻印的时光 ゝ 提交于 2020-01-06 08:18:12

问题


I have checkbox inside a repeater and repeater is placed inside of an update panel. The checkbox have an checked changed event and I need the id of the checkbox so I can state it in autopostbacktrigger inside triggers. But I can't access the id as it is placed inside the repeater. How can I get the id of the checkbox?

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <div class="row">
            <div class="col-md-4">
                <div style="padding-top: 10px; padding-left: 20px;">
                    <asp:Panel runat="server" Style="height: 300px;" ID="pnl1" Visible="false" CssClass="panel pre-scrollable panel-default mypnl">
                        <!-- Default panel contents -->
                        <div class="panel-heading">
                            Job Status List
                                    <div class="pull-right">
                                        <a style="margin-top: -5px;" data-toggle="modal" data-target="#myModal" class="col-xs-12 btn btn-sm btn-default"><i class="glyphicon glyphicon-plus"></i></a>
                                    </div>
                        </div>
                        <!-- List group -->
                        <ul class="list-group">
                            <asp:Repeater ID="rep1" runat="server" OnItemDataBound="rep1_ItemDataBound">
                                <ItemTemplate>
                                    <li class="list-group-item">
                                        <%# Eval("Description")%>
                                        <div class="pull-right">
                                            <asp:CheckBox runat="server" AutoPostBack="true" OnCheckedChanged="chkstatus_CheckedChanged" ChkDesc='<%# Eval("Description")%>' ChkId='<%# Eval("ID")%>' ID="chkstatus" />
                                        </div>
                                    </li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                    </asp:Panel>
                </div>
            </div>
            <div class="col-md-8">
                <div style="padding-top: 10px; padding-left: 0px;">
                    <asp:Panel runat="server" Style="height: 166px;" ID="pnl2" Visible="false" CssClass="panel pre-scrollable panel-default">
                        <!-- Default panel contents -->
                        <div class="panel-heading">
                            Job Sequence
                        </div>
                        <!-- List group -->
                        <ul class="list-group">
                        </ul>
                    </asp:Panel>
                </div>
            </div>

        </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="chkstatus" EventName="Checked" />
    </Triggers>
</asp:UpdatePanel>

回答1:


You only need to register them if you want to trigger a normal PostBack if they are inside the UpdatePanel.

But you find them like this:

foreach (RepeaterItem item in rep1.Items)
{
    CheckBox cb = item.FindControl("chkstatus") as CheckBox;
    ScriptManager.GetCurrent(Page).RegisterPostBackControl(cb);
    //or
    ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(cb);
}


来源:https://stackoverflow.com/questions/48439266/how-to-get-the-checkbox-id-that-placed-in-a-repeater-for-update-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!