Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2005
    Thanked 1 Time in 1 Post

    Question Web Page Global Variables

    I just learned that using Global Variables is a VERY BAD IDEA in Web Page application because it tends to cause issues when multiple users are on the page at the same time accessing
    and trying to use that particular variable.

    I was instructured to use one of the following:
    - use a cookie
    - use Session["var"]
    - just use a class variable in your page code!!
    - (with possible Server.Transfer)": use Context["var"]
    - use a ViewState["var"] variable or a hidden TextBox
    - use Application["var"]

    Therefore the "page class member variable"
    However I am really unfamilar with these nor do I know which is the best to use in my situation.

    Currently my web application have a calendar, users can connect and select a date for a task to run, so I could have many users scheduling various tasks at the same time.
    The DateTime needs to be saved, currently I was using Global Variables as defined previouslly (which is supposdly BAD).

    Can someone tell me which method I should be using (and possible why) and maybe an example on how I could apply this to me DateTime varable (dtSelected).


  2. #2
    Regular Coder
    Join Date
    Dec 2004
    Thanked 0 Times in 0 Posts
    I think if you are talking about storing data Permanently or for any extended period of time you should consider Database Methods.

    Thing is Application variables are open for all users on your site to see its contents. For example I used application variables to keep a track of which users were on my site on a particular time.

    Session variables on the hand are created independent of any other session for each user that logs on to your site. When a user requests your site from the server, the server creates a session specifically for that user. Each session has a timeout and it gets destroys after the timeout has elasped. This is generally used to store SMALL amounts of data and it is global in the sense that the variable can be accessed from whatever the user is on given the timeout has not elasped.

    The other methods I don't like or are not familiar with. Server.execute just pauses processes of one page.... processess another in the parentheses and then resumes processing of the main page. Don't see how that is even relevant. Cookies you could maybe do some reading on but I don't know too much to comment about that but my suggestion is this:

    If you are thinking of storing data, and if you are thinking of going larger scale at any point in time in terms of your site. You're gonna need physical storage, because you cannot rely on any of the variables i mentioned earlier to store any large amounts of data. Possibly cookies might be a interesting solution and you could do some reading but I SUGGEST DATABASE!!!!

    I'm gonna find a way to download the internet if its the last thing I do...
    Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

  3. #3
    Regular Coder
    Join Date
    Aug 2002
    Thanked 2 Times in 2 Posts
    I often use session variables for things like storing what the user entered (if anything) for search fields on a form.

    Session("CustomerDialog-LName") = Request.Form("LName")
    Session("CustomerDialog-CompanyName") = Request.Form("CompanyName")

    And then on the page to show the data:

    ' Set strSQL.
    strSQL = "SELECT * FROM tblCustomer WHERE (1=1)"
    If Session("CustomerDialog-LName") <> "" Then
    strSQL = strSQL & " AND (Rep='" & Session("CustomerDialog-LName") & "')"
    End If
    If Session("CustomerDialog-CompanyName") <> "" Then
    strSQL = strSQL & " AND (Customer='" & Session("CustomerDialog-CompanyName") & "')"
    End If
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

  4. #4
    Senior Coder
    Join Date
    Apr 2003
    Thanked 13 Times in 13 Posts
    that can be useful for securely storing data if you have a form continuing on multiple pages but make sure you wipe teh sessions as much as possible and dont set the timeout too high and do not store a lot of data on it, im with jaywhy on this one, a database sounds like its really what you are looking for


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts