How static variables are stored?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #16
    That doesn't actually have two different values.
    Each page load stores it's value in that static, then spits it back out to the page.
    The next page overwrites that value with it's own, then shows it again.
    That is not a valid test.

    Comment

    • Murugs
      New Member
      • Nov 2007
      • 18

      #17
      Hi Plater,
      Just update the static variable on some condition and check it again.
      its maintaining different values.
      check the below code.

      GlobalVariables .userName = "Value not changed";
      Response.Write( GlobalVariables .userName);
      if (Request.QueryS tring["Id"] == "1")
      {
      GlobalVariables .userName="valu e changed";
      Response.Write( GlobalVariables .userName);
      }

      run the application in two ies.
      Now pass the Id =1 as querystring in one ie.

      Now check you can have different values.
      Let me know if you are not understand my question..pls do some sample before reply so u can able to know my question well.
      Thanks..

      -Murugs

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #18
        Originally posted by Murugs
        Hi Plater,
        Just update the static variable on some condition and check it again.
        its maintaining different values.
        check the below code.

        GlobalVariables .userName = "Value not changed";
        Response.Write( GlobalVariables .userName);
        if (Request.QueryS tring["Id"] == "1")
        {
        GlobalVariables .userName="valu e changed";
        Response.Write( GlobalVariables .userName);
        }

        run the application in two ies.
        Now pass the Id =1 as querystring in one ie.

        Now check you can have different values.
        Let me know if you are not understand my question..pls do some sample before reply so u can able to know my question well.
        Thanks..

        -Murugs

        AGAIN, you are SETTING the value each time and overwriting the previous value. You don't see it happening because it will print it out before the next page is loaded

        Create a page with two buttons and label.
        Code:
        protected void Page_Load(object sender, EventArgs e)
        {
           MyLabel.Text=GlobalVars.thinger;
        }
        protected void btChange_Click(object sender, EventArgs e)
        {
           GlobalVars.thinger = Request.RawUrl;
        }
        protected void btView_Click(object sender, EventArgs e)
        {//do nothing
        }
        Make sure you have something like:
        Code:
        public static class GlobalVars
        {
           public static string thinger="";
        }
        Then you can do your two broswers test, changing the querystring and using the "change" button to set the global variable and use the View button to view it.

        Comment

        • Murugs
          New Member
          • Nov 2007
          • 18

          #19
          Atlast got it.its all coz of wrong testing..
          Thanks Plater..

          Comment

          Working...