0
votes

I've spent quite a while searching this problem, there are some other similar threads online but none have helped me fix it.

I have a GridView with an ImageButton within it, the imagebutton has an OnClick function but that event is never reached when it is clicked, below is my gridview:

<asp:GridView ID="gridBuildings" runat="server" AutoGenerateColumns="False"
              GridLines="none" ShowFooter="false" ShowHeader="false" 
              Width="100%">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton runat="server" ID="cmdBuy"
                     ImageUrl="~/images/button.jpg" 
                     OnClick="ImageButton_Click"/>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

and here's the code-behind (I've removed the extra content, the response.redirect is never hit when the ImageButton is clicked)

Protected Sub ImageButton_click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
    response.redirect("test.aspx")
    Dim row As GridViewRow = Me.gridBuildings.SelectedRow
    (etc ... )
End Sub

There is a form runat="server" tag in the master page, as well as an asp:UpdatePanel and an asp:AjaxScriptManager I have a feeling the problem might be something to do with a postback but just can't work it out - any help would be appreciated.

Thanks!

1
the gridview is inside the updatepanel? have you tried to disable the updatepanel to see if it's the problem? - tanathos
yep - i got rid of the updatepanel soon after writing this post, not sure why i had it in one. thanks though - jdtaylor

1 Answers

1
votes

Make sure you are not rebinding the grid every page load. If you rebind, the event will never fire. Wrap the binding statement in an if not ispostback block.