如何执行在ASP.Net Web表单回传操作 [英] How to perform postback operation in ASP.Net Webforms

查看:184
本文介绍了如何执行在ASP.Net Web表单回传操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行回发来获取数据时,&LT时; DIV ID =roomTypeContainer方式>点击结果
所以,把它包在的LinkBut​​ton 。当我点击 DIV ,有一个在浏览器控制台错误。

I want to perform a postback to get data, when the <div id="roomTypeContainer"> is clicked.
So, wrapped it inside a LinkButton. When I click on the div, there is an error in the browser console.

未捕获类型错误:theForm.submit不是一个函数

Uncaught TypeError: theForm.submit is not a function

中继器是用户控件

ASCX:

<asp:Repeater ID="rpRoomTypes" runat="server" ItemType="Sitecore.Data.Items.Item"
 OnItemDataBound="rpRoomTypes_ItemDataBound" OnItemCommand="rpRoomTypes_ItemCommand">
   <ItemTemplate>
     <sc:EditFrame ID="efRoomType" runat="server" >
      <asp:LinkButton ID="lnkRoomType" runat="server" CommandName="cmd_RoomType">
       <div id="roomTypeContainer" runat="server">
          ..some html
       </div> 
      </asp:LinkButton>
    </sc:EditFrame>
  </ItemTemplate> 
</asp:Repeater>

更新:
当我点击浏览器控制台错误链接,这code显示在控制台:

UPDATE: When I click the error link in browser console, this code is shown in console:

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['mainform'];
if (!theForm) {
    theForm = document.mainform;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit(); //error here
    }
}
</script>

以上code似乎是由Sitecore的产生。 的MainForm 为形式的ASPX页面的ID。

The above code seems to be generated by Sitecore. mainform is the id of form in aspx page.

然在控制台相同的脚本,这里是结果

Ran the same script in console and here is the result

推荐答案

看着这条线在生成的JS:

Looking at this line in the generated JS:

var theForm = document.forms['mainform'];

theForm是一个全局变量设置为页面加载,但我不知道,如果表单元素还没有在那个时候创建​​(或脚本块来后 - 这将导致问题太)。然后,当函数在doPostback运行,theForm.submit功能不会因为存在,即使窗体现在是存在,变量引用它仍然是空

theForm is a global variable set at page load, but I wonder if the form element is not yet created at that time (or comes after the script block - that would cause the issue too). Then, when the function runs in the doPostback, theForm.submit function will not exist since, even though the form is now in existence, the variable referencing it is still null.

在控制台中,只需键入theForm和preSS输入(无控制台分配吧),看看它设置为。如果是空/未定义,那么这就是所发生的事情,在这种情况下,需要更多的信息来诊断故障(例如,为什么尚未创建的形式)。

In the console, just type theForm and press enter (without assigning it in the console) and see what it is set to. If it's null/undefined, then that's what's happening, in which case more info is needed to diagnose the failure (for example, why is the form not yet created).

这篇关于如何执行在ASP.Net Web表单回传操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆