ASP.NET WebForm上的Jquery Ajax加载表单 [英] Jquery Ajax loading form on asp.net webform

查看:166
本文介绍了ASP.NET WebForm上的Jquery Ajax加载表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用$ .load()在父.aspx的div上加载.aspx页面.加载内容后,将在aspnetForm内部的代码中放置一个新表单.我之前已经以非常类似的方式完成了此操作,但是这次Submit按钮将新表单提交到了Ajax加载页面,而不是aspnetForm父页面.

I'm loading using $.load() a .aspx page on a div of a parent .aspx, let's say. When the content is loaded a new form is placed in the code, inside the aspnetForm. I've done this before in a very similiar way, but this time the submit button is submitting the new form to the ajax loaded page, not the aspnetForm parent page.

更多详情

当用户从列表中选择一组项目时,它们将由ajax加载,如下所示:

When the user choose a set of items from a list, they're loaded by ajax like this:

$("#gvContacts").load("MailingContacts.aspx?ids="+$("#filters").val() + "&removedContacts=" + $("#removedContacts").val() + "&action=<%=Convert.ToInt16(this.Action) %>", function());

MailingContacts是一个内部带有GridView的aspx WebForm.当.load将HTML放到div上时,它是这样的:

MailingContacts is a aspx webForm with a GridView inside. When the .load puts the HTML on the div it goes like this:

<form id="form1" action="MailingContacts.aspx?ids=11&amp;removedContacts=&amp;action=2" method="post" name="form1">
<!-- GridView code -->

</form>

出于某种原因,提交页面的按钮正在使用此新表单,而不是原始的aspnetForm.

and for some reason, the Button that submits the page is using this new form instead of the original aspnetForm.

推荐答案

不允许使用嵌套表单-如果在主父表单中添加一组新的<form>标记,则最终会导致痛苦的世界.

You're not allowed to have nested forms - if you add a new set of <form> tags inside the main parent form you'll end up in a world of pain.

基本上,您通过在客户端创建嵌套表单来绕过服务器端对此的验证.我想象您的提交按钮将使用它在页面上找到的最后一个表单操作,而不是父"操作.

Basically, you're bypassing the server-side validation of this by creating the nested form in the client side. I imagine that your submit button is then using the last form action it finds on the page, rather than the "parent" action.

您应该:

  1. 将JavaScript创建的表单加载到ASP.NET主表单控件之外的<div>中(允许在页面上使用多个表单,只是不嵌套).
  2. 以一种可以处理MailingContacts表单内容的方式构建主表单,并从中删除Form标记.
  3. 与其返回整个HTML页面(包括基于AJAX的GridView),还不如返回用户详细信息的集合,并使用jQuery将其呈现到列表中,等等-您发送的数据要比发送所有这些都要多HTML.
  1. Load the JavaScript created form into a <div> outside of the main ASP.NET form control (you are allowed multiple forms on a page, just not nested).
  2. Build your main form in such a way that it can handle the form contents of MailingContacts, and remove the Form tags from it.
  3. Rather than returning a whole page of HTML including a GridView over AJAX, just return collection of user details, and render them into a list with jQuery, etc - you're sending a lot more data than you need to sending all that HTML.

这篇关于ASP.NET WebForm上的Jquery Ajax加载表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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