如何将通过 Javascript 添加的表行发布到 ASP.NET 中的服务器? [英] How to post table rows, added via Javascript, to the server in ASP.NET?

查看:18
本文介绍了如何将通过 Javascript 添加的表行发布到 ASP.NET 中的服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前有人问过这个问题:访问 <asp:table>由 javascript 在 asp.net webform 中添加的表格行.为重复的问题道歉,但我真的很想解释为什么会这样.可能是因为我对浏览器如何处理提交给服务器的 HTML 表格缺乏了解.

如果我有一个 <HTML>table 或 在 aspx 页面上控制,我使用 JQuery/Javascript 在客户端向它添加行,为什么我不能在回发到服务器时包含这些添加的行?

我一直在努力让它发挥作用,但根据上一个问题的答案,我似乎无法做到这一点.但是有人可以解释为什么会这样吗?表格本身可以在回发中返回,但唯一存在的行是最初发送到浏览器时属于表格一部分的行 - 它不包括浏览器添加的行.

我原以为有一种方法可以在回发中包含这些新行,就像任何客户端用户输入一样?

解决方案

当对服务器执行 POST 操作时,只有包含在被发布的

元素中的值将被包含在内.这些被序列化为键/值对,可以使用像 FireBugChrome 开发者工具.

常规 HTML 元素不会发送回服务器.我的意思是像

元素不会返回到服务器,只有表单的值.

不幸的是,ASP.Net 对您隐藏了很多这些细节.太神奇了!坏事.它可以让您轻松愉快地工作,而无需了解 HTTP 在幕后如何工作的具体细节,但当您确实需要了解这些细节时,这可能会成为痛苦的根源.

This question has been asked before: Access <asp:table> table rows added by javascript in asp.net webform . Apologies for the duplicate question but I'd really like an explanation why this is the case. It is probably due to my lack of understanding on how browsers process HTML tables on submission to the server.

If I have a <HTML> table or an <asp:table> control on an aspx page and I add rows to it client-side using JQuery / Javascript, why can I not include these added rows in a post-back to the server?

I've been trying to get this to work and it looks like I can't do it based on the answer to the previous question. But can someone explain why this is the case? The table itself can be returned in the post-back but the only rows present are the rows that were part of the table when it was sent to the browser originally - it does not include the rows added by the browser.

I would have thought there was a way to include these new rows in the post-back, the same as any client-side user input?

解决方案

When performing a POST operation to the server, only the values included withing the <form> element being posted will be included. These are serialized as Key/Value pairs and can be inspected using tools like FireBug and the Chrome Developer Tools.

Regular HTML elements are not sent back to the server. What I mean is that things like <div> or <table> elements don't go back to the server, only the values of the form.

Unfortunately ASP.Net hides a lot of these details from you. It is magic! That is both a good and a bad thing. It makes it easy to work blissfully ignorant of the nitty gritty details of how HTTP works under the hood, but can be a source of pain when you really need to know those details.

这篇关于如何将通过 Javascript 添加的表行发布到 ASP.NET 中的服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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