I know what you’re thinking, why would anyone do that anyway. Believe me, I am one of them, but to understand how I got to this point you need to understand the project I am working on. For some reason our client has a few different web sites and right now we are making changes to one of them. What they wanted us to do was make this site look like one of their other ones. No problem, but when I asked what the other site looked like I was simply told to go to a url. This pretty much meant that I would be getting none of the style or pictures in an email or anything else for that matter which left me the option of “view source” on the browser. So I viewed a few pages to see what would be needed in the master page and to get the location of the styles and images and went from there. I know, this is probably the worst way to do this but the sad thing is if I waited for the client to send that stuff over .Net 5 might come out before I get it. Not to mention the site was done in PHP so I had a hard time knowing what was Html and what was generated on the server.
I got the style of the master page down and started on the content for the home page. I copied the source from the browser and went from there. I then started to focus on changing one thing at a time rather than focusing on the whole page at once. I added some login controls and changed a few links. I assumed there would be a logout link on this page so I added a LoginStatus control to the page. I only added it to test the logout functionality since I didn’t know if the page would have different items showing based on whether or not the user was logged in, I can tell you’re jealous of this style of development already. Logging in worked just as expected but when I clicked the logout link nothing happened. I noticed there was a javascript error so I investigated further. The error was “object does not support property or method”.
I didn’t know what to think. I thought the LoginStatus might be broke but that would be ridiculous. So I added it to another page and it all worked fine. I then thought I would just add a link button and log the user out in the code behind. Still didn’t work. I then thought about how the login button work just fine and confined the problem to just link buttons. Which brings me to the root of the problem.
As you know form generated by Asp.Net contains a few lines of javascript that look like this:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
since LinkButtons are generated as “a” tags and not submit buttons they call this function to do a post back. The problem with my particular page was that I had not replaced an element that was named “submit” so when the form called submit it was trying to call the element like a method rather than trying to submit the form, crazy stuff. Obviously I was already not happy about having to develop like this so you can imagine how happy I was to spend some more time to dive into this error.