asp:Button is not calling server-side function

Posted by Richard Neil Ilagan on Stack Overflow See other posts from Stack Overflow or by Richard Neil Ilagan
Published on 2010-04-27T17:07:47Z Indexed on 2010/04/27 17:13 UTC
Read the original article Hit count: 245

Filed under:
|

Hi guys,

I know that there has been much discussion here about this topic, but none of the threads I got across helped me solve this problem. I'm hoping that mine is somewhat unique, and may actually merit a different solution.

I'm instantiating an asp:Button inside a data-bound asp:GridView through template fields. Some of the buttons are supposed to call a server-side function, but for some weird reason, it doesn't. All the buttons do when you click them is fire a postback to the current page, doing nothing, effectively just reloading the page.

Below is a fragment of the 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>

The viewBtn above should call the viewBtnClick() function on server-side. I do have that function defined, along with a proper signature (object,EventArgs). One thing that may be of note is that this code is actually inside an ASCX, which is loaded in another ASCX, finally loaded into an ASPX.

Any help or insight into the matter will be SO appreciated. Thanks!

(oh, and please don't mind my trashy HTML/CSS semantics - this is still in a very,very early stage :p)

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET