I have a pretty simple ASP.NET Web Form that looks a bit like the following:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="example.aspx.cs" Inherits="example" %>
<form runat="server">
<asp:GridView runat="server" id="grid" AutoGenerateColumns="false" OnRowCommand="DoStuff">
<Columns>
<asp:ButtonField Text="Do stuff" />
</Columns>
</asp:GridView>
</form>
(In PageLoad I call grid.DataBind()
, and the event handler DoStuff
is unremarkable.)
When I view this in Internet Explorer and click the ButtonField (which renders as a link), the event handler fires as expected. When I click it in Firefox, nothing happens.
If I turn on Firebug's Javascript debugging console then click the link, it shows an error in the Javascript onclick
handler that's auto-generated by ASP.NET:
theForm is undefined
__doPostBack("grid", "$0")
javascript:__doPostBack('grid', '$0')()
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {\r\n
Why does this happen and how can I make the ButtonField work in Firefox?
(N.B. I'm asking this question in order to answer it myself: I've already discovered why I was seeing the above error, and wanted to record it for the benefit of myself and others. Feel free to add other answers if you know other gotchas with ASP.NET and Firefox.)