ASP.NET页面变量持久性 [英] ASP.NET Page Variables Persistence

查看:78
本文介绍了ASP.NET页面变量持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在设计一个ASP.NET应用程序,其中特定页面需要在回发期间需要保留的全局变量。这样做的最佳做法是什么?


是使用viewstate对象还是将变量声明为静态(我目前正在使用此方法)?


谢谢,


Mark Anthony Spiteri

Hi,

I am designing an ASP.NET application in which particular pages require global variables that need to be persisted during postbacks. What is the best practice to do this?

Is it to use the viewstate object or is declaring the variables as static sufficient (I am currently using this method)?

Thank you,

Mark Anthony Spiteri

推荐答案

2004年6月26日星期六08:08:01 -0700,Mark Anthony Spiteri

< mark @ [remove] mspiteri.com>写道:
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:


我正在设计一个ASP.NET应用程序,其中特定页面需要在回发期间需要持久化的全局变量。执行此操作的最佳做​​法是什么?

是使用viewstate对象还是将变量声明为静态(我目前正在使用此方法)?
Hi,

I am designing an ASP.NET application in which particular pages require global variables that need to be persisted during postbacks. What is the best practice to do this?

Is it to use the viewstate object or is declaring the variables as static sufficient (I am currently using this method)?




您需要使用ViewState对象,或者可能是Session

对象。静态变量是不够的 - 在Web环境中,每个请求都会重新启动

应用程序,因此您的静态变量

正在重新初始化。


Gareth



You''ll need to use the ViewState object, or perhaps the Session
object. A static variable isn''t enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth


感谢您的回复。


" Gareth Jones"写道:
Thank you for your reply.

"Gareth Jones" wrote:
2004年6月26日星期六08:08:01 -0700,Mark Anthony Spiteri
< mark @ [remove] mspiteri.com>写道:
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:


我正在设计一个ASP.NET应用程序,其中特定页面需要在回发期间需要持久化的全局变量。执行此操作的最佳做​​法是什么?

是使用viewstate对象还是将变量声明为静态(我目前正在使用此方法)?
Hi,

I am designing an ASP.NET application in which particular pages require global variables that need to be persisted during postbacks. What is the best practice to do this?

Is it to use the viewstate object or is declaring the variables as static sufficient (I am currently using this method)?


<你需要使用ViewState对象,或者可能是Session
对象。静态变量是不够的 - 在Web环境中,
应用程序会针对每个请求重新启动,因此您的静态变量正在重新初始化。

Gareth



You''ll need to use the ViewState object, or perhaps the Session
object. A static variable isn''t enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth



感谢您的回复


" Gareth Jones"写道:
Thank you for your reply

"Gareth Jones" wrote:
2004年6月26日星期六08:08:01 -0700,Mark Anthony Spiteri
< mark @ [remove] mspiteri.com>写道:
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:


我正在设计一个ASP.NET应用程序,其中特定页面需要在回发期间需要持久化的全局变量。执行此操作的最佳做​​法是什么?

是使用viewstate对象还是将变量声明为静态(我目前正在使用此方法)?
Hi,

I am designing an ASP.NET application in which particular pages require global variables that need to be persisted during postbacks. What is the best practice to do this?

Is it to use the viewstate object or is declaring the variables as static sufficient (I am currently using this method)?


<你需要使用ViewState对象,或者可能是Session
对象。静态变量是不够的 - 在Web环境中,
应用程序会针对每个请求重新启动,因此您的静态变量正在重新初始化。

Gareth



You''ll need to use the ViewState object, or perhaps the Session
object. A static variable isn''t enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth



这篇关于ASP.NET页面变量持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆