views:

141

answers:

3

I am upgrading a project from ASP.NET 1.1 to ASP.NET 2.0. In my aspx page, I have a hidden field, like this:

<input type="hidden" name="__TabControlAction" />

And I have the following javascript function:

function __tabStripPostBack(key) {
var theform;

if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
 theform = document.forms["Form1"];
}
else {
    theform = document.Form1;
}
    theform.__TabControlAction.value='Click';
    theform.__TabControlKey.value=key;
    theform.submit();
}

In ASP.NET 1.1, this code works fine. However, now that I upgraded to ASP.NET 2.0, I get "__TabControlAction is null or not an object" error. For whatever reason, it seems the javascript can't find the hidden field, even though its there. Anyone have any ideas?

A: 

Is theform still defined? You might need to try this when you declare theform:

 theform = document.forms['aspnetForm'];

In other words, check your generated HTML to see what the name and id attributes of your <form> tag are.

JerSchneid
I did. It says form1. I tried replacing it with ['aspnetForm'] anyway. Still the same error.
icemanind
Try putting a line after you set theform, like this `alert(theform);` Knowing whether or not that is null will help narrow your problem.
JerSchneid
+1  A: 

I think the name of the form should be "aspnetForm", not "Form1". You should be able to directly refer to it since this bit of javascript is injected on every form with a runat="server" tag.

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

Try changing your code to this:

function __tabStripPostBack(key) {
    theForm.__TabControlAction.value='Click';
    theForm.__TabControlKey.value=key;
    theForm.submit();
}
tvanfosson
A: 

Rather than referencing this through the form, can you give your input element an id and use document.getElementById('yournewid'); ?

Aaron Daniels