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, for example:
<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 have upgraded to ASP.NET 2.0, I get the error "__TabControlAction is null or not an object". For some reason, it seems that javascript cannot find the hidden field even though its there. Does anyone have any ideas?
+1
a source to share
3 answers
I think the name of the form should be "aspnetForm" and not "Form1". You should be able to link to it directly as this bit of javascript is injected into every form with the 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();
}
+1
a source to share