[英]I get a “Microsoft JScript runtime error: Object doesn't support this property or method” error for anything with autopostback=true on one of my pages
I have a .NET application with the following aspx code: 我有一个带有以下aspx代码的.NET应用程序:
<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default"%>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ToolkitScriptManager>
<table>
<tr>
<td>
<asp:RadioButtonList ID="rblTest" runat="server" AutoPostBack="True"
onselectedindexchanged="rblTest_SelectedIndexChanged">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:PlaceHolder ID="ph1" runat="server" Visible="False">
Some text
</asp:PlaceHolder>
</td>
</tr>
</table>
</form>
</body>
</html>
I then have a C# method as follows: 然后,我有一个C#方法,如下所示:
protected void rblTest_SelectedIndexChanged(object sender, EventArgs e)
{
if (rblTest.SelectedValue == "2")
ph1.Visible = true;
else
ph1.Visible = false;
}
Below is where the crash occurred. 以下是发生崩溃的地方。 It crashes any time I use a control that has autopostback=true.
每当我使用具有autopostback = true的控件时,它就会崩溃。 I use the same syntax on about 15 other forms and those all work just fine.
我在大约15种其他形式上使用了相同的语法,并且所有这些都很好用。 Am I missing a property somewhere or is there something wrong with my method?
我在某处缺少属性还是我的方法有问题? I originally had an UpdatePanel around the controls and I plan on adding it again, but I need to get the postback working first.
我最初在控件周围有一个UpdatePanel,我打算再次添加它,但是我需要首先使回发工作。
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['Default'];
if (!theForm) {
theForm = document.Default;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit(); <-----Crashed at this line.
}
}
//]]>
</script>
What am I missing or is there some common mistake that I may have made somewhere? 我错过了什么,或者我可能在某个地方犯了一些常见的错误? Thanks in advance for your help.
在此先感谢您的帮助。
Your __doPostBack
script is trying to submit a form with id "Default"
(see document.forms["Default"]
line; yet your markup shows a form with id "form1"
so it's clear why it doesn't work: the __doPostBack
function is not finding the form and calling theForm.submit()
fails. 您的
__doPostBack
脚本正在尝试提交ID为"Default"
的表单(请参见document.forms["Default"]
行;但是您的标记显示的表单为ID为"form1"
的表单,因此很清楚为什么它不起作用: __doPostBack
函数找不到表单,调用theForm.submit()
失败。
You can attempt to fix it by renaming the form to use the id "Default"
since I don't think you can control the way the __doPostBack
script is generated. 您可以尝试通过重命名表单以使用ID
"Default"
来修复它,因为我认为您无法控制__doPostBack
脚本的生成方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.