Icemanind
Icemanind

Reputation: 48736

ASP.NET and Javascript Error

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?

Upvotes: 1

Views: 1628

Answers (3)

Aaron Daniels
Aaron Daniels

Reputation: 9664

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

Upvotes: 0

tvanfosson
tvanfosson

Reputation: 532765

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();
}

Upvotes: 1

JerSchneid
JerSchneid

Reputation: 5917

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.

Upvotes: 0

Related Questions