公共变量问题 [英] public variable problem
本文介绍了公共变量问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题:
这是使用Visual Studio 2005
我有一个声明为公共成员的DataSet:
public DataSet tmp
在我的Page_Load中填充DataSet。
我随时尝试在Page_Load之外访问此DataSet,例如
Wizard1_FinishButtonClick
DataSet为null 。
知道为什么会这样吗?
问候,
史蒂文
***通过开发人员指南发送 http://www.developersdex.com ***
Hi,
Here is my problem:
This is using Visual Studio 2005
I have a DataSet declared as a public member:
public DataSet tmp
In my Page_Load I populate the DataSet.
Anytime I try to access this DataSet outside the Page_Load, e.g
Wizard1_FinishButtonClick
The DataSet is null.
Any idea why this happens?
Regards,
Steven
*** Sent via Developersdex http://www.developersdex.com ***
推荐答案
嗨史蒂文,
你有没有机会使用过''不是在你的Page_Load中回传'?
if(!IsPostback)
{
//填写你的数据集
}
如果是这样,那么你的数据集只会被填充第一次,而不是任何
回发。
HTH
Christiaan
" Steven布莱尔" < ST ********** @ btinternet.com> schreef in bericht
新闻:uB ************** @ TK2MSFTNGP15.phx.gbl ...
Hi Steven,
Do you have by any chance used the ''not is postback'' in your Page_Load ?
if (!IsPostback)
{
//fill of your dataset
}
If so, then your dataset will only be filled the first time, and not on any
postback.
HTH
Christiaan
"Steven Blair" <st**********@btinternet.com> schreef in bericht
news:uB**************@TK2MSFTNGP15.phx.gbl...
>
这是我的问题:
这是使用Visual Studio 2005
我有一个声明为公共成员的DataSet:
public DataSet tmp
在我的Page_Load中填充DataSet。
我随时尝试在Page_Load之外访问此DataSet,例如
Wizard1_FinishButtonClick
DataSet为空。
知道为什么会这样吗?
问候,
Steven
***通过开发人员指南 http://www.developersdex.com 发送***
是的,我的DataSet最初填充在
if(!IsPostBack)
{
//填充数据集
}
我只想填充一次,这就是为什么它在这里。
我正在使用向导组件o每次用户更改页面时都会调用Page_Load。
当然只有一个MyForm类实例存在,并且每次调用后都会调用
Page_Load ,这是否意味着存在一个新实例?
我尝试将我的DataSet声明为静态,并允许我访问
数据,但对我而言毫无意义。
你能解释一下这里发生的一些事情吗?
***通过开发者指数发送 http://www.developersdex.com ***
Yeah my DataSet is initially populated inside
if (!IsPostBack)
{
//Fill DataSet
}
I only ever want it filled once, thats why its in here.
I am using a Wizard component so Page_Load gets called each time user
changes a page.
Surely only one instance of MyForm class exists, and after every call of
Page_Load, does this mean a new instance exists?
I tried declaring my DataSet as static, and that allows me to access the
data, but to me that makes no sense.
Can you explain in some detail whats happening here?
*** Sent via Developersdex http://www.developersdex.com ***
发布Page_Load事件的代码,我打赌你宣布另一个具有相同名称的
变量并且它优先。
>
欢呼,
-
Ignacio Machin,
ignacio.machin at dot.state.fl。我们
佛罗里达州交通部
" Steven Blair" < ST ********** @ btinternet.com>在消息中写道
news:uB ************** @ TK2MSFTNGP15.phx.gbl ...
Hi,
Post the code for the Page_Load event, I bet you are declaring another
variable with the same name and it takes precedence.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Steven Blair" <st**********@btinternet.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
>
这是我的问题:
这是使用Visual Studio 2005
我有一个声明为公共成员的DataSet:
public DataSet tmp
在我的Page_Load中填充DataSet。
我随时尝试在Page_Load之外访问此DataSet,例如
Wizard1_FinishButtonClick
DataSet为空。
知道为什么会这样吗?
问候,
Steven
***通过开发人员指南 http://www.developersdex.com 发送***
这篇关于公共变量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文