简体   繁体   English

使用vb.net处理客户端和服务器端

[英]Dealing with client side and server side using vb.net

The problem im having is that I have a table that when a user click on a button it adds a row to the table via javascript, which works fine. 我遇到的问题是,我有一个表,当用户单击按钮时,它会通过javascript向表中添加一行,效果很好。 The problem is that if a user need to update other data the user click another button which refreshes the page and all rows the user created in the table are deleted. 问题是,如果用户需要更新其他数据,则单击另一个按钮刷新页面,然后删除用户在表中创建的所有行。 My question is what can I do to make the rows not to be deleted once the page is refreshed? 我的问题是,刷新页面后,如何使行不被删除? I know some might think, just not refresh the page, but there is to much data that has to be displayed and a new query has to be generated to grab the data. 我知道有些人可能会认为,只是不刷新页面,而是要显示很多数据,并且必须生成新查询来获取数据。 Any help would be very much appreciated. 任何帮助将不胜感激。

Thanks for all the comments. 感谢所有的评论。 I thought I would edit my question b/c ppl are asking why dont you add it via server or via ajax. 我以为我会编辑我的问题b / c ppl,问您为什么不通过服务器或ajax添加它? The reason is b/c I ran into a problem doing it that way on another application and I will explain the problem. 原因是b / c在另一个应用程序上这样做时遇到问题,我将解释问题。 When I add a row via server-side it worked great, but what I started to noticed it that some users would add up to 100 rows and it would get very slow and even time out, b/c every time a user would add a row, it would have to re-create all those rows everytime which caused it to timeout. 当我通过服务器端添加一行时,效果很好,但是我开始注意到,有些用户最多可以添加100行,并且变得非常缓慢,甚至超时,每次用户添加一个行时b / c行,则每次都必须重新创建所有导致行超时的行。 That why I wanted to add rows via javascript(client-side) b/c you dont have to re-create all those rows everytime a user adds another row. 这就是为什么我想通过javascript(客户端)b / c添加行的原因,所以不必在用户每次添加另一行时都重新创建所有这些行。 If there is another way of handling this without slowing down the page or potentially timing out the page, please let me know. 如果还有另一种处理方法,而又不减慢页面速度或可能导致页面超时,请告诉我。 Its kinda driving me crazy!!! 有点让我疯狂!!! I have been an ASP programmer for years and kind of newer to .Net and it seems like there is no way around this 我多年来一直是ASP程序员,并且是.Net的较新版本,似乎没有办法解决这个问题

You need to make the server aware that you've added a column to the table. 您需要使服务器知道您已向表中添加了列。 There are many ways to do this. 有很多方法可以做到这一点。

Each time you post-back to the server (because HTTP is stateless) it begins from the start, so it generates a fresh table for you. 每次回发到服务器时(因为HTTP是无状态的),它都是从头开始的,因此它将为您生成一个新表。

To do this you need to execute some code on the server, the easiest way is to add the row on the server and not on the client as you currently are. 为此,您需要在服务器上执行一些代码,最简单的方法是在服务器上而不是在客户端上添加行

If you post how your table is being generated - we'll be able to point you in the right direction. 如果您发布表格的生成方式-我们将为您指明正确的方向。

2 realistic methods here: 这里有2种现实方法:

1) Don't reload the page. 1)不要重新加载页面。 If you do a get from a script you can simply return json or xml and parse it within the javascript 如果您从脚本获取内容,则只需返回json或xml并在javascript中对其进行解析

2) Post to the server when you are adding a new row such that it is saved and can be used later when refreshing the page 2)在添加新行时将其发布到服务器,以便将其保存并在以后刷新页面时使用

Use html5 localstorage to keep the value of your rows on the client, on every refresh recreate the rows from localstorage using javascript. 使用html5 localstorage可以在客户端上保留行的值,每次刷新时都使用javascript从localstorage重新创建行。

As a side note, unless you either have a LOT of rows or a lot of data in the rows, server side shouldn't be particularly slow and either case will make localstorage unusable. 附带说明一下,除非您有很多行或行中有很多数据,否则服务器端应该不会特别慢,并且任何一种情况都将使localstorage无法使用。

Alternative, serverside store the data in a session variable, but do not return it as part of your main page, use ajax to retrieve it seperately client side and put it in your page (with paging if a lot of rows). 或者,服务器端将数据存储在会话变量中,但不要将其作为主页的一部分返回,请使用ajax分别在客户端将其检索并将其放在您的页面中(如果有很多行,则使用分页)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM