Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6852013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:19:10+00:00 2026-05-27T01:19:10+00:00

is there an easy way, to store all needed global variables in sessions at

  • 0

is there an easy way, to store all needed global variables in sessions at once, before the PostBack starts? Or have I to store them in each step where I change them?
I will do something like:

// Global variable.
bool test = true;

// Store all needed information in a session.
protected void Before_globalvariable_is_set_to_default_value(...)
{
    Session["Test"] = test;
    ...
}

protected void Page_Load(object sender, EventArgs e)
{
    if(IsPostBack)
    {
        //if(Session["Test"] != null)
        //{
            test = (bool)Session["Test"];
            Session.Contents.Remove("Test");
        //}
    }
}

Is something like that possible?

Additional Information

At the Page_Load (!IsPostBack) I check if the user gets more vision, if he gets, I set a global var to true. Later in my code I check if that var is true and add additional columns to a GridView.
Now if a PostBack occurs, I can’t check that var, because I lose the information. I knew that I need to store the information in a Session. If I set the Session at the time where I set the global var to true, I get problems with the session timeout (If the user is on the site, but doesn’t do something for a while). So I thought it will be good, if I set the Session shortly before I lose the information of the global var and delete the Session after reinitialization.

That’s my idea, but I don’t know if something like that is possible.

Edit2:
If I do following it works:

//Global variable
bool test = false;

protected void Page_PreRender(object sender, EventArgs e)
{
    Session["Test"] = test;
}

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        test = (bool)Session["Test"]; // Session is true!!!
        Session.Contents.Remove("Test");
    }
    else
    {
        test = true; // Set at the PageLoad the var to true.
    }
}

I’m a little bit confused, I thought PreRender is after the PageLoad, why suddenly the test var is true and if I remove the PreRender it isn’t?

Greetz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:19:10+00:00Added an answer on May 27, 2026 at 1:19 am

    If you’re worried about losing a specific value between requests, because you’ve maintained the state of that variable in the Session object and it might have been cleared by a timeout, you could consider using another, more durable, mechanism to save the state: for example, cookies or database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way to copy all stored procedures from one database to
is there any easy way of store XML data into core data? Currently, my
Is there any easy way to access the SVN repository revision number and store
Is there an easy way to chase down table/stored procedure/function dependencies in SQL Server
Is there easy way to send email notification with cruise control? I Was reading
Is there any easy way to exchange the position of 2 elements - or
Is there an easy way to add shadows in opengl-es 1.x? Or only in
Is there an easy way to migrate a hosted LAMP site to Amazon Web
Is there an easy way how can I get in C char * from
Is there an easy way to iterate over an associative array of this structure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.