Everything in Particular

January 24, 2009

TheForm is undefined / not defined error in asp.net

Filed under: Uncategorized — omatase @ 9:22 pm

`I just spent about 3 hours trying to fix this error with the LoginStatus control. The control updates fine when I log in, but when I click the “Logout” link on the LoginStatus control I wasn’t getting a postback. After a little more looking I noticed I was getting a javascript error whenever I clicked Logout. The error I was getting was “TheForm is undefined”. I googled and googled and googled and ultimately I didn’t find the fix for my problem on google but I did find a lot of different solutions to the problem. I am consolidating them with the solution for me all in one place so that hopefully noone else has to go through this.
Scenario 1

Make sure when including external Javascript files like so:

[code lang='html']
[/code]
Scenario 2

The script created by Asp.Net references your form by id. Make sure your form id matches what is shown in the javascript generated. For instance mine had to be named Aspnetform so I made sure it looked like:

[code lang='html']

[/code]

I also read that the id is case sensitive so make sure that is correct as well.
Scenario 3

Make sure your form has a runat="server" attribute as follows

[code lang='html']

[/code]
Scenario 4

This is the one that got me. I had my form defined outside of my <body> tag. My HTML looked like this:

[code lang='html']



[/code]

This will not work. Swap the order of your tags to be thusly:

[code lang='html']

[/code]

Hope this helps someone else.

5 Comments »

  1. thank you so much.. it worked.

    Comment by coldfront2006 — July 2, 2009 @ 9:26 am

  2. Great info … On my page, the BODY and FORM tags were in the wrong order. Fixing that eliminated the error.

    Comment by Ben Amada — October 20, 2009 @ 11:27 pm

  3. cant believe it was because of the wrong closing tag! thanks!!

    Comment by pablo — October 28, 2009 @ 8:34 am

  4. Thanks a bunch.

    Comment by Amar — October 29, 2009 @ 8:08 am

  5. Thank you so much!! First scenario worked!! Saved me a lot of time. Thanks!

    Comment by Jignesh — January 29, 2010 @ 1:45 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress