简体   繁体   English

在两页之间传递数据集或数据表

[英]Passing dataset or datatable between two pages u

I've a popup to enter the data and once the data is added, I need to show data in parent page Gridview. 我有一个弹出窗口来输入数据,一旦添加了数据,就需要在父页面Gridview中显示数据。 But that data don't need to be stored until I click the save button below the Gridview in the parent page. 但是,直到我单击父页面中Gridview下方的保存按钮,才需要存储该数据。 It will still be displayed and maintained on the screen - (like it has active/inactive button). 它仍将在屏幕上显示和维护-(例如具有活动/不活动按钮)。

When I click the save below the gridview, it will be stored in the database all at once. 当我单击gridview下面的保存时,它将立即全部存储在数据库中。 I need to do this using javascript. 我需要使用javascript做到这一点。 How can I do that? 我怎样才能做到这一点?

I'm working on asp.net web project. 我正在asp.net Web项目上。

You can save your data temporarily using localStorage instead of your database for instance: 您可以使用localStorage代替数据库来临时保存数据,例如:

localStorage.setItem('myDataName', 'myDataValue') // Save data

And: 和:

localStorage.getItem('myDataName') // Get data

This works for strings. 这适用于字符串。 If you want to save objects or arrays of objects, you must convert them to strings like this: 如果要保存对象或对象数组,则必须将它们转换为如下字符串:

localStorage.setItem('myDataName', JSON.stringify(myObject)) // Save object

Take a look at LocalStorage 看看LocalStorage

The localStorage property allows you to access a local Storage object. localStorage属性允许您访问本地存储对象。 localStorage is similar to sessionStorage. localStorage与sessionStorage类似。 The only difference is that, while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the browsing session ends—that is, when the browser is closed. 唯一的区别是,尽管存储在localStorage中的数据没有到期时间,但是在浏览会话结束时(即,在关闭浏览器时),存储在sessionStorage中的数据将被清除。

It should be noted that data stored in either localStorage or sessionStorage is specific to the protocol of the page. 应该注意的是,存储在localStorage或sessionStorage中的数据特定于页面协议。

Store Data 存储数据

localStorage.setItem('Key', 'YOUR_DATA');

Read Data 读取资料

var YOUR_DATA = localStorage.getItem('Key');

You can also store objects by stringifying it. 您也可以通过对对象进行字符串化存储。

localStorage.setItem('Key', JSON.stringify(YOUR_DATA_OBJ));

when reading parse to object 在读取解析为对象时

var YOUR_DATA_OBJ = JSON.parse(localStorage.getItem('Key'));

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

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