简体   繁体   English

ASP.NET和Javascript错误

[英]ASP.NET and Javascript Error

I am upgrading a project from ASP.NET 1.1 to ASP.NET 2.0. 我正在将项目从ASP.NET 1.1升级到ASP.NET 2.0。 In my aspx page, I have a hidden field, like this: 在我的aspx页面中,我有一个隐藏字段,如下所示:

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

And I have the following javascript function: 而且我有以下javascript函数:

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. 在ASP.NET 1.1中,此代码可以正常工作。 However, now that I upgraded to ASP.NET 2.0, I get "__TabControlAction is null or not an object" error. 但是,现在我已升级到ASP.NET 2.0,我收到“ __TabControlAction为空或不是对象”错误。 For whatever reason, it seems the javascript can't find the hidden field, even though its there. 无论出于何种原因,似乎javascript都无法找到隐藏字段,即使该字段存在。 Anyone have any ideas? 有人有想法么?

I think the name of the form should be "aspnetForm", not "Form1". 我认为表单的名称应该是“ aspnetForm”,而不是“ 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. 您应该能够直接引用它,因为在每一种表单中都使用runat =“ server”标签注入了javascript语言。

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

Is theform still defined? theform仍然定义吗? You might need to try this when you declare theform : 声明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. 换句话说,检查生成的HTML以查看<form>标记的nameid属性。

Rather than referencing this through the form, can you give your input element an id and use document.getElementById('yournewid'); 您可以给输入元素一个ID并使用document.getElementById('yournewid');而不是通过表单引用它。 ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM