Forum  General Visual ...  Let's Chat Abou...  Global Variable question/Clarification
Previous Previous
 
Next Next
New Post 5/15/2009 3:10 PM
  palli
11189 posts
1st Level Poster




Re: Global Variable question/Clarification 

Hi,

Ryan's example shows you how you would set variables within your mainform to store this information for you, and then you would need to be calling the GetContextVariable function, knowing some control within that form, like when you're calling it from a button handler or something like that.

If that is not acceptable, that function should be easily converted to use VWGContext.Current.MainForm to get to the mainform and provide the same functionality as Ryan is suggesting.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 5/15/2009 3:33 PM
  rdhatch
635 posts
1st Level Poster




Re: Global Variable question/Clarification 
Modified By rdhatch  on 5/15/2009 5:34:09 PM)

Hi Palli -

I didn't think of geting the MainForm from the VWGContext directly.  No need to pass the control anymore.  That is perfect, Thanks!!

Ryan


Ryan D. Hatch, VWG MVP
GeniusCode.net | VWG Community Frameworks | VWG Wiki
 
New Post 5/15/2009 3:38 PM
  palli
11189 posts
1st Level Poster




Re: Global Variable question/Clarification 

Hi Ryan,

Where there is a problem, there is always a way... you're welcome :-)

Palli


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 5/16/2009 9:45 PM
  osmosis311
383 posts
3rd Level Poster


Re: Global Variable question/Clarification 

 Hi Palli and Ori,

I'm sorry that I am not understanding what is being discussed here.

If you can explain about the context and application variables as simply as possible :-)

Currently, I have a web application that users log into.  I created a Module (Module1) where I am storing Public variables, such as UserID and UserName, etc.  

Are these variables on a per-web-user basis?  Or will each user that logs into the application be sharing these variables?

I never knew it was like this before!

So if I want to properly store variables on a per user basis, meaning, each user that is logging into my application, I have to use VWGContext.Current?

 

Thanks!

 
New Post 5/17/2009 3:20 PM
  palli
11189 posts
1st Level Poster




Re: Global Variable question/Clarification 
Modified By palli  on 5/17/2009 5:27:09 PM)

Hi Danny,

I will try to explain....

First, static variables are global and are shared between every instance of the application. Module in VB.NET is static, and variables declared in there are shared between all users of your application. I think it's safe to say that static variables are living in the Application scope, in that sense.

Of the 3 reimaining storage scopes, the Cookie scope should be easily understood, which leaves us with the Session and Context storage scopes. There is a difference between browsers and even browser versions on how they treat this, but let's take Firefox as an example. Firefox runs all it's tabs, and all it's windows within one single process on your PC. Even if you open a new window in FF, you are running in the same process on your client PC. This is a little different from some version of IE for instance, where a new process is started on your client if you open a new IE window, but if you open a new tab, you'll use the same process.

The info about the browsers is relevant when you open a session to your web application. In FF (which uses the same process for all) will use the same session to connect to your app in all it's tabs and all it's windows.

Now to the VWGContext. Context in VWG is defined as a mainform and what's being done in there. If you access your app via two ways, http://yourapp/Form1.wgx and http://yourapp/Form2.wgx, you will have one Context when you access via Form1 and another context when accessing via Form2 .... but both will have the same Session (within FF or new tab in IE or IE version that doesn't create new process).

As for storing your variables in a safe "local" place, in an application that has 2 mainforms, and therefor has 2 VWGContexts you have three options:

  1. If you want both the forms to access the same variables, you can use the Session context. Think of for instance how you set the IsLoggedOn flag via Context.Session.IsLoggedOn = True. This goes for both forms, meaning if you log into one, you are logged into the other. But then you must of course store your user credentials in a session variables also, so you can retrieve them when you start the second form.
  2. If you want each of your MainForms (Form1 and Form2 above) to have it's own sets of variables, you can declare your variables locally within the form. They will then be local to the instance of your form.
  3. Again, same as in number 2 above, you can save your variables to the VWGContext, which gives you one set of variables for each of your forms too.

So this all depends on your requirements.

My usual approach is that I use Session variables to store the name of the logged on user, but try to keep the info stored there as small as possible. Setting Context.Session.IsLoggedOn = True and then Context.Session("UserName") = "loggedinuser" should be enough in most cases.

Then in my mainforms I keep a variable local to the form, with additional information required for info about the user. I most often have it in special class and read extra info in from a Database when I know the user is logged on.I then create an instance of that class in the Form's load event, and store the instance in a variable local to the form.

This approace is just one of many possibilities, but it makes those information local to each VWGContext (that is MainForm) I have in my app.

Hope this gives you some understanding and helps a little.

Feel free to ask if you need any more explainations.

Palli

 

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
Previous Previous
 
Next Next
  Forum  General Visual ...  Let's Chat Abou...  Global Variable question/Clarification
CompanionKit Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS