ASP.NET中的FORM表单产生的JS错误问题,如何解决?

chequan 2004-05-06 05:02:44
在aspx页面中我直接调用的用户控件,比如:
<mybbs:forumhome id="forumhome1" runat="server" />
然后在用户控件forumhome中是完整的页面内容,比如:
<html>
<title>mybbs</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<form id="Form1" method="post" runat="server">

<asp:LinkButton id="LinkButton1" runat="server">LinkButton</asp:LinkButton>

</form>
</body>
</html>
然而访问页面出现js错误。调试发现错误在于:
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["forumhome:Form1"];
}
else {
theform = document.forumhome:Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>
这个js函数,而且就是其中的
theform = document.forms["forumhome:Form1"];

theform = document.forumhome:Form1;
这两个语句出错。其实可能问题就在于forumhome:Form1在js中是错误的表达式。
产生的HTML代码中的FORM部分为
<form name="forumhome:Form1" method="post" action="index.aspx" id="forumhome_Form1">
请问这个问题该如何解决,谢谢!
...全文
108 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
chequan 2004-05-07
  • 打赏
  • 举报
回复
但问题是我不能去掉该控件呀。请问有其它的解决办法吗?
Seeko0 2004-05-07
  • 打赏
  • 举报
回复
以前也有人问过想同的问题,原因可能就是在你设计的用户控件里面包含了form控件,去掉该控件即可
chequan 2004-05-07
  • 打赏
  • 举报
回复
我是页面上没有Form,只在用户控件中有Form,因此整个aspx也就相当于只有一个Form
WZCNet 2004-05-07
  • 打赏
  • 举报
回复
确保用户控件中没有<form></form>标记,因为一个页面只能有一个Form,你现在的页面有了,用户控件中就不能要,否则会出错的。
vzxq 2004-05-07
  • 打赏
  • 举报
回复
帮你UP
udonome 2004-05-07
  • 打赏
  • 举报
回复
用户控件放到<form></form>中去
chequan 2004-05-07
  • 打赏
  • 举报
回复
1、根据页面模板的需求,需要将form写在控件中,而不是写在aspx中
2、__doPostBack是系统生成的,我没法修改的呀!

谢谢!请各位帮我顶顶!!!
Seeko0 2004-05-07
  • 打赏
  • 举报
回复
在用户控件中去掉form控件,在*.aspx中加入form控件;
或者你可以试着改写一次
function __doPostBack(eventTarget, eventArgument) {
var theform;
theform = document.forms[0];
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
chequan 2004-05-06
  • 打赏
  • 举报
回复
大家快帮我看看,谢谢了!!!
chequan 2004-05-06
  • 打赏
  • 举报
回复
没有。调用控件的页面就只有一个调用控件的语句,比如:
<mybbs:forumhome id="forumhome1" runat="server" />
其它什么也没有。因此产生的整个html文件也就只有一个form。
vzxq 2004-05-06
  • 打赏
  • 举报
回复
学习,帮你UP
wanwenguo 2004-05-06
  • 打赏
  • 举报
回复
调用这个控件的页面是不是也有一个Form?

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧