Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 352939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:47:02+00:00 2026-05-12T11:47:02+00:00

I have a pretty simple ASP.NET Web Form that looks a bit like the

  • 0

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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:47:02+00:00Added an answer on May 12, 2026 at 11:47 am

    This is due to a difference in how the browsers handle Javascript in the presence of invalid HTML: specifically, when the form is not surrounded with <html> and <body> tags. Without these tags, Firefox seems to try to initialise the variable theForm before the form actually exists.

    Adding the proper <html> and <body> tags around the form (as is required for valid HTML in any case) makes the click handler work in both IE and Firefox.

    Notes:

    • obviously invalid HTML is a worst practice for many other reasons. The page I was developing was intended to be used with a Master page which rendered the rest of the surrounding HTML, but (for various reasons) I was testing it in isolation from the Master page.
    • I tried reproducing the same problem with a simple <asp:Button runat="server">, but that triggers a full page-refreshing PostBack, so it doesn’t hit the same error. Being a Web Forms n00b I don’t know what’s special about a GridView (or this use case) that makes it behave differently (i.e. sets up an onclick handler to handle the click without a page load).
    • I’ve marked this as wiki in case anyone else can explain this better than I.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.