Hi Group,
I would like to trigger a PostBack when the asp:LinkButton "addToCartButton" is clicked (see code below).
I have declared a PostBack Trigger with the asp:UpdatePanel "updPnlProductsList" (see code below).
<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. -->
Unfortunately, when I run this code I get the error:
InvalidOperationException: A control with ID 'addToCartButton' could not be found for the trigger in UpdatePanel 'updPnlProductsList'.
Would someone please help me reference the 'addToCartButton' within the ItemTemplate of the DataList.
Or maybe I can cause a PostBack in the asp:LinkButton code behind? I'm coding in C#.
Kind Regards
Walter