![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Re: life and scope of variables in vb.net?
> Private MyClassVariable as String = "Hello World" > > Public Sub DisplayMessage > DisplayMessageLabel.Text = MyClassVariable > End Sub > > Public Sub DisplayMessageAnotherMessage > DisplayMessageAnotherMessage.Text = MyClassVariable > End Sub > Presuming that first line is defined at the very top of the codebehind outside any of the Subs. But If I set it at the class level, but what's available to me when I set it? At the time I'm setting it, do I have access to session variables? Do I have access to values of controls on the page? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: life and scope of variables in vb.net?
Jason <> wrote in news:4fee0da0-d85f-420d-a193-
: > But If I set it at the class level, but what's available to me when I > set it? At the time I'm setting it, do I have access to session > variables? Do I have access to values of controls on the page? When you declare at class level, the variable is created in the constructor of the page. At this point, you do not have access to session variables, cookies, etc. yet, but I think you can access controls after Initializecomponent is called. However, in the constructor you could execute database queries or any other non-ASP.NET code and populate the variables. If you need to populate class variables with ASP.NET data, wait for the Page_Init or Page_Load fire. By this point of the page lifecycle, the ASP.NET session variables, cookies, etc should be populated in HTTPContext. Does this answer your q? -- (Do not e-mail) |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |