且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET - 保护变量

更新时间:2023-11-27 19:49:58

当你移动到其他页面和回报,你的页面类的新实例将被创建,因此所有的非静态变量将被重置。

when you move to other page and return, a new instance of your page class will be created and so all non static variables will be reset.

该值将在一个请求过程续航时间有效(始于请求开始和结束时要求结束)

The value will be valid in a one request process life time (starts with request start and ends with request end)

做保护的变量,就意味着这个变量的访问能够继承类。例如在asp.net您可以在继承类使用它像您的标记里面(因为它继承了后面类code)

making a variable protected, just means that this variable is access-able in inherited class. for example in asp.net you can use it in inherited class like inside your markup (because it inherits code behind class)

这是受保护的变量的含义。

this is the meaning of protected variable

如果你想保留保存的网页之间的值,您可以使用您的具体要求,其中一个项目:

if you want to keep a value saved between pages you can use one of these items depending on your requirement :


  • 饼干

  • 查询字符串

  • 会话状态

  • 申请美国

  • 缓存

和ViewState中保持在同一页或控件回发之间的状态变量,而它不重定向到另一个页面。

and ViewState keeps state variable between postback in a same page or control while it is not redirected to another page.