简体   繁体   English

c# ASP.NET 持久数据,即使页面刷新

[英]c# ASP.NET Persistant Data even with page refresh

I have a asp.net page with c# code behind.我有一个 asp.net 页面,后面有 c# 代码。 I have a first panel where the user selects and enters information, they then click continue and that data is stored in variable.我有一个第一个面板,用户在其中选择并输入信息,然后他们单击继续,该数据存储在变量中。 A new panel displays on screen and the select some new data which when they click continue stores that data in that panel and sends all the information to a c# program.屏幕上会显示一个新面板,select 会显示一些新数据,当他们单击继续时,会将这些数据存储在该面板中,并将所有信息发送到 c# 程序。 The problem I an getting is that when I click continue the first time and the page refreshing showing only the new panel all the data defaults to 0. How can I fix this?我遇到的问题是,当我第一次单击继续并且页面刷新仅显示新面板时,所有数据默认为 0。我该如何解决这个问题?

Thanks谢谢

HTML is a connectionless protocol. HTML 是一种无连接协议。 This means there is no state.这意味着没有 state。 There are ways to mimic state with .net, but html has no means of this by default.有一些方法可以用 .net 模仿 state,但默认情况下 html 没有这种方法。 If you are using webforms, you can utilize viewstate as long as you are posting back to the same page each time.如果您使用的是网络表单,则只要您每次都回发到同一页面,就可以使用视图状态。 If you are using mvc, you will either have to submit your data via ajax or you will have to send all the initial data you sent to the server back to the view so when you press continue you can populate it all again.如果您使用的是 mvc,您要么必须通过 ajax 提交数据,要么必须将发送到服务器的所有初始数据发送回视图,因此当您按下继续时,您可以再次填充所有数据。 Or just use jQuery/javascript to hide(), show() portions of your page, but wait till everything is completed prior to posting to the server.或者只是使用 jQuery/javascript 来隐藏()、显示()页面的部分,但要等到一切都完成后再发布到服务器。

Good luck祝你好运

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

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