提交后表丢失的 jQuery DOM 操作
基于文本框“自动完成”功能,用户可以在结果列表中进行选择,然后用户将选择这些结果之一并将其添加到“篮子”中,用户执行多次快速搜索并从该篮子中添加或删除项目。
目前我使用一张桌子作为“篮子”。一旦用户对购物篮感到满意,用户就将购物篮提交给服务器,服务器循环浏览购物篮并更新数据库。
我正在尝试使用 jQuery 操作表,问题是一旦发生回发,DOM 操作就会被删除。
该表如下所示。
<asp:Table ID="Basket"
runat="server"
EnableViewState="False">
<asp:TableHeaderRow TableSection="TableHeader">
<asp:TableHeaderCell>ID</asp:TableHeaderCell>
<asp:TableHeaderCell>Name</asp:TableHeaderCell>
<asp:TableHeaderCell>Quantity</asp:TableHeaderCell>
</asp:TableHeaderRow> </asp:Table>
使用 jQuery,我可以修改表、添加行、删除它们,一切都很好。 有一个提交按钮
然后,我在循环按钮的 Click 事件中 通过我表的行
foreach (TableRow row in this.Basket.Rows)
{
if (row.TableSection != TableRowSection.TableBody) { continue; }
}
这就是问题所在,表被重置为仅包含 1 行的初始状态。考虑到我已经禁用了 ViewState,我认为该控件会模仿回发的内容。但显然有什么东西让它重置。
Based on a TextBox "autocomplete" functionality the user can select amongst a list of results, the user would then select one of theese results and add it to a "basket", the user performs multiple rapid searches and adds or removes items from this basket.
At the moment i've used a table as the "Basket". once the user is satisfied with the basket, the user submits the basket to the server and the server loops trough the basket and updates the database.
I'm trying to manipulate a table with jQuery, the problem is that once the postback happens, the DOM manipulations are removed.
The table looks like the following.
<asp:Table ID="Basket"
runat="server"
EnableViewState="False">
<asp:TableHeaderRow TableSection="TableHeader">
<asp:TableHeaderCell>ID</asp:TableHeaderCell>
<asp:TableHeaderCell>Name</asp:TableHeaderCell>
<asp:TableHeaderCell>Quantity</asp:TableHeaderCell>
</asp:TableHeaderRow> </asp:Table>
with jQuery i can modify the table, add rows, delete them and all is fine and dandy. I then have a submit button
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
in the Click event of the button i loop through the rows of my table
foreach (TableRow row in this.Basket.Rows)
{
if (row.TableSection != TableRowSection.TableBody) { continue; }
}
This is where the problem is, the Table is reset to the initial state only containing 1 row. Considering i've disabled the ViewState, I would think the control would mimic what is posted back. But clearly something makes it reset.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的想法是错误的,Javascript 是前端,如果你不告诉服务器行已被添加,它永远不会知道,因此它只会按照你的指示添加一行。
您需要以某种方式保存这些值
You are thinking about this all wrong, Javascript is front end and without you telling the server that rows have been added, it will never know and thus it only adds one row as you tell it to do.
You will need to save the values somehow