简体   繁体   中英

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. 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. The reason is b/c I ran into a problem doing it that way on another application and I will explain the problem. 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. 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. 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

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.

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:

1) Don't reload the page. If you do a get from a script you can simply return json or xml and parse it within the 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

Use html5 localstorage to keep the value of your rows on the client, on every refresh recreate the rows from localstorage using javascript.

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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