Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When I click the image button 'imgPaymentMethod' I require the code to change the ImageUrl of the Image Button. However, nothing happens when clicked.

<asp:GridView ID="gdvItems" runat="server" AutoGenerateColumns="False"
     DataKeyNames="fileID" DataSourceID="DSUploadedItems" CssClass="mGrid"
     AlternatingRowStyle-CssClass="alt">
 <AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
     <Columns>
         <asp:TemplateField visible="true" HeaderText="Price">
             <ItemTemplate>
                 <asp:DropDownList ID="ddlBuyPrice" runat="server" AutoPostBack="True" Font-Size="11px" Height="22px" OnSelectedIndexChanged="ddlBuyPrice_SelectedIndexChanged" SelectedValue='<%# Bind("buyPrice")%>'>
                      <asp:ListItem Value="0.00">Select:</asp:ListItem>
                 </asp:DropDownList>
                 <asp:LinkButton visible="false" ID="lnkPaymentMethod" runat="server" CausesValidation="False"
                     Text='<%# Bind("acceptPaypal")%>' > /></asp:LinkButton>
                 <br /><br />
                 <asp:Label ID="lblSoldStatus" visible="false" runat="server" CausesValidation="False" Text='<%# Bind("sold") %>' />
                 <asp:Image ID="imgSoldStatus" alt="Sold Status" runat="server" width="100px" ImageUrl="~/files/images/icons/iconSold.png" />
                 <br />

                 <asp:UpdatePanel ID="upPnlControls" style="margin-top:0px;" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
                     <Triggers>
                         <asp:AsyncPostBackTrigger controlid="imgPaymentMethod" eventname="Click" />
                     </Triggers>
                     <ContentTemplate>
                         <asp:ImageButton visible="true" ID="imgPaymentMethod" runat="server" CausesValidation="False" width="50px" onclick="lnkPaymentMethod_Click"></asp:ImageButton>
                     </ContentTemplate>
                 </asp:UpdatePanel>

                 <br />
                 <asp:Label ID="lblDateBought" runat="server" CausesValidation="False" Text='<%# Bind("dateBought") %>' />
                 <asp:LinkButton ID="lnkMarkAsSold" runat="server"  OnClick="markAsSold_Click" Text="Mark As Sold" Visible="true" ></asp:LinkButton>
             </ItemTemplate>
         </asp:TemplateField>
     </Columns>
 </asp:GridView>


VB Code..

Protected Sub lnkpaymentMethod_Click(sender As Object, e As System.EventArgs)
    Dim imgPaymentMethod As ImageButton = CType(sender, ImageButton)
    Dim currentRow As GridViewRow = DirectCast(imgPaymentMethod.Parent.Parent, GridViewRow)

    If imgPaymentMethod.ImageUrl="~/files/images/icons/paypalIcon.gif" Then
        imgPaymentMethod.ImageUrl="~/files/images/icons/cashIcon.gif"
    Else
        imgPaymentMethod.ImageUrl="~/files/images/icons/paypalIcon.gif"
    End If

End Sub


What I have tried:

I have tried moving the Gridview inside the Update Panel but then I get this error:
Quote:
A control with ID 'imgPaymentMethod' could not be found for the trigger in UpdatePanel 'upPnlControls'
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900