I create an asp: Button inside a data bound asp: GridView through the template fields. Some of the buttons should call a function on the server side, but for some strange reason this is not the case. All buttons, when you click on them, start the postback to the current page, doing nothing, just reloading the page.
The following is a snippet of code:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" CssClass="l2 submissions" ShowHeader="false"> <Columns> <asp:TemplateField> <ItemTemplate><asp:Panel ID="swatchpanel" CssClass='<%# Bind("status") %>' runat="server"></asp:Panel></ItemTemplate> <ItemStyle Width="50px" CssClass="sw" /> </asp:TemplateField> <asp:BoundField DataField="description" ReadOnly="true"> </asp:BoundField> <asp:BoundField DataField="owner" ReadOnly="true"> <ItemStyle Font-Italic="true" /> </asp:BoundField> <asp:BoundField DataField="last-modified" ReadOnly="true"> <ItemStyle Width="100px" /> </asp:BoundField> <asp:TemplateField> <ItemTemplate> <asp:Button ID="viewBtn" cssclass='<%# Bind("sid") %>' runat="server" Text="View" OnClick="viewBtnClick" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
In the viewBtn above, call the server-side viewBtnClick () function. I have a specific function, as well as the correct signature (object, EventArgs). You may notice that this code is actually located inside ASCX, which is loaded into another ASCX, finally loaded into ASPX.
Any help or understanding of this issue would be greatly appreciated. Thanks!
(oh, and please ignore my murky HTML / CSS semantics - this is still at a very early stage: p)
source share