使用 __doPostBack() 进行回发时遇到错误
我在回发时遇到 javascript 错误。代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!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">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function DoPostBack()
{
__doPostBack('Button2','My Argument');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" id="Button2" value="Press me" onclick="DoPostBack()" />
</form>
</body>
</html>
我收到以下错误:
Line: 13
Error: Object expected
我无法理解为什么会出现此错误。请帮忙...
I am getting an error on javascript when doing post back. The code is as follows:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!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">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function DoPostBack()
{
__doPostBack('Button2','My Argument');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" id="Button2" value="Press me" onclick="DoPostBack()" />
</form>
</body>
</html>
I am getting the following error:
Line: 13
Error: Object expected
I can't understand why this error is coming. Kindly help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用隐藏按钮来执行此任务
隐藏按钮后
您可以从 javascript 调用其单击函数
这将在服务器上调用 Button1_Click
** 请记住设置
UseSubmitBehaviour=false
以使此功能在非IE 浏览器希望有帮助:)
you can use a hidden button to do this task
after hiding the button
you can call its click function from javascript
this will call Button1_Click on server
** remember to set
UseSubmitBehaviour=false
to make this work on non-IE browsershope that helps :)
默认情况下不创建 __doPostBack。如果页面没有导致回发的控件,则 ASP.NET 不会创建/生成此方法。
在您的情况下,您可以通过在 Page_Load 事件中添加以下行来强制 ASP.NET 生成 __doPostBack:
此行将强制创建此方法。
__doPostBack is not created by default. If the page does not have a control that causes a postback then ASP.NET does not create/generate this method.
In your case you can force ASP.NET to generate __doPostBack by adding the following line in you Page_Load event:
This line will force the creation of this method.
默认情况下不创建 _doPostBack。当您使用 autoPostBack=true 添加控件或添加一些带有按钮的网格时,它会出现。
所以你的代码中没有生成 _doPostBack javascript。
如果您添加,
例如, 您的代码就会起作用。
不知道它是否真的有用的代码:)但是。
_doPostBack isn't created by default. It appears when you are adding control with autoPostBack=true or adding some grid with buttons in it.
So there is no _doPostBack javascript generated in your code.
If you add
for instance your code will work.
Don't know if it is really useful code :) however.