asp : LinkButton "addToCartButton"을 클릭하면 포스트 백을 트리거하고 싶습니다 (아래 코드 참조).InvalidOperationException : PostBack 트리거가 DataList의 ItemTemplate에서 컨트롤을 찾을 수 없음
나는 asp : UpdatePanel "updPnlProductsList"(아래 코드 참조)로 포스트 백 트리거를 선언했습니다.
경우 InvalidOperationException : ID 'addToCartButton'와 컨트롤이 UpdatePanel 'updPnlProductsList'에서 트리거를 찾을 수 없습니다 나는이 코드를 실행하면
<asp:Panel ID="pnlProductsList" runat="server" Visible="false">
<asp:UpdatePanel ID="updPnlProductsList" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="featured">
<h3>Product listing</h3>
<div class="product clearfix">
<asp:DataList ID="productsList" runat="server" DataKeyField="prodid" OnItemCommand="productsList_ItemCommand"
OnItemDataBound="productsList_ItemDataBound">
<HeaderTemplate>
<table>
<col width="85" />
<col width="315" />
<col width="85" />
<col width="315" />
<col width="85" />
<tr>
<th align="left">
</th>
<th align="left">
Product Description
</th>
<th align="center">
In Stock
</th>
<th align="center">
Price
</th>
<th align="left">
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td height="85" valign="top">
<asp:HyperLink ID="standardImage" Style="float: left; margin-right: 5px; border: 2px;
vertical-align: top;" Width="75" Height="75" runat="server"></asp:HyperLink>
</td>
<td height="85" valign="top">
<asp:LinkButton ID="lbProductDescription" CommandName="show_product" runat="server" />
<p>
<asp:Label ID="MfPartNo" runat="server" /></p>
</td>
<td height="85" align="center" valign="top">
<p>
<asp:Label ID="inventoryTextLabel" runat="server" /></p>
</td>
<td style="padding-bottom: 10px;" height="85" align="center" valign="top">
<div class="product-actions clearfix">
<p class="price">
<strong>
<asp:Label ID="sellPriceLabel" runat="server" Style="font-size: 0.9em;" /></strong>
</p>
</div>
</td>
<td style="padding-bottom: 10px;" height="85" valign="top">
<div class="product-actions clearfix">
<p class="view">
<asp:LinkButton ID="addToCartButton" runat="server" Text="<span><strong>Buy</strong></span>"
CommandName="add_to_cart" class="newactionbutton" />
</p>
</div>
</td>
</tr>
</div>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan="5" style="border-bottom: dotted 1px gray; line-height: 0.1em;">
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="addToCartButton" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<!-- /The all new Products List. -->
불행하게도, 나는 오류가 발생합니다.
누군가가 DataList의 ItemTemplate 내에서 'addToCartButton'을 참조하도록 도와 주시겠습니까?
또는 어쩌면 내가 뒤에있는 ASP : LinkButton 코드에서 포스트 백을 일으킬 수 있습니까? 나는 C#으로 코딩하고있다.
친절 감사
월터
당신의 빠른 응답을위한 감사의 joerage. 내가 어떻게 할 수 있는지 설명해 주시겠습니까? –
안녕하세요. 이 코드를 뒤에 코드에 추가하려고 시도했습니다. protected void productsList_ItemDataBound (Object sender, DataListItemEventArgs e) { // productsList의 onItemDataBound 이벤트를 처리합니다. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { ScriptManager scriptManager = ScriptManager.GetCurrent (this.Page); scriptManager.RegisterPostBackControl (e.Item.FindControl ("addToCartButton")); } 작동하지 않았습니다. 같은 오류. –
안녕하세요. 나는 이것을 시도했다 : protected void productsList_ItemDataBound (Object sender, DataListItemEventArgs e) { // productsList의 onItemDataBound 이벤트를 처리한다. 경우 (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { 제어 컨트롤 = NULL; control = e.Item.FindControl ("addToCartButton"); PostBackTrigger trigger = 새 PostBackTrigger(); trigger.ControlID = control.ID; updPnlProductsList.Triggers.Add (trigger); } } 하지만 같은 오류로 인해 실패했습니다. –