TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Notices

Re: life and scope of variables in vb.net?

VB.NET


Reply
 
Thread Tools Display Modes
Old 15-12-2007, 12:19 AM   #1
Jason
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?
  Reply With Quote
Old 15-12-2007, 12:20 AM   #2
Spam Catcher
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)
  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 06:12 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional