我在转发器中有复选框,转发器放在更新面板内。该复选框有一个已检查更改的事件,我需要复选框的ID,以便我可以在autopostbacktrigger内部触发器中声明它。但我无法访问id,因为它被放置在转发器内。如何获取复选框的ID?
<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>
答案 0 :(得分:2)
如果要在UpdatePanel内部触发正常的PostBack,则只需要注册它们。
但你发现他们是这样的:
foreach (RepeaterItem item in rep1.Items)
{
CheckBox cb = item.FindControl("chkstatus") as CheckBox;
ScriptManager.GetCurrent(Page).RegisterPostBackControl(cb);
//or
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(cb);
}