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 3808062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:05:21+00:00 2026-05-19T15:05:21+00:00

I’ve got an index page which sends users to an edit products page on

  • 0

I’ve got an index page which sends users to an edit products page on separate browser tabs.

For each products edited the index rewrites the Session[“ProductID”].

The Edit page then has the following code to have a unique identifier for this tab and product:

if (!IsPostBack) //first time page load
{
    Random R = new Random(DateTime.Now.Millisecond + DateTime.Now.Second * 1000 + DateTime.Now.Minute * 60000 + DateTime.Now.Minute * 3600000);
    PageID.Value = R.Next().ToString();

    Session[PageID.Value + "ProductID"] = Session["ProductID"];
}

This works, and when the same user opens multiple tabs I only reference the Session[PageID.Value + “ProductID”] in my code so that I always have the proper ID. (I’m working in a trusted environment this is for an intranet, therefore I’m not too bothered with the level of security).

My issue occurs if the user does a page refresh by hitting the F5 key. At which point the Session[PageID.Value + “ProductID”] gets the Session[“ProductID”] of the last product he opened.

For example:

User 1 opens product1 in tab1

User 1 opens product2 in tab2

Whenever they use the tool normally, everything works fine. However if:

User 1 on product1 page hits the refresh button (F5) the product1 page becomes product2 page

Is there a way to detect a page refresh from a “first load/redirect from another page” so that I can then tell my page not to update my Session[PageID.Value + “ProductID”]?

  • 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-19T15:05:22+00:00Added an answer on May 19, 2026 at 3:05 pm

    I’ve solved a very similar issue by storing two versions of a state-identifying parameter: one in Session and one in either the ViewState or the URL (QueryString).

    If you compare the two values on Page_Load, that will tell you whether the session variable has changed since the page was first loaded. This should be just what you need.

    EDIT: Rough sketch of the code (warning – haven’t seen the actual code since I wrote it 3 years ago):

    protected string currentProductID
    {
        get
        {
            return Request.QueryString["ProductID"];
            //or: 
            //return (string)ViewState["ProductID"];
            //or:
            //return HiddenField1.Value;
        }
        set
        {
            Response.Redirect(ResolveUrl("~/MyPage.aspx?ProductID=" + value));
            //or:
            //ViewState.Add("ProductID", value);
            //or: 
            //HiddenField1.Value = value;
        }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        //If the problem only occurs when not posting back, wrap the below in
        // an if(!IsPostBack) block. My past issue occurred on both postbacks
        // and page refreshes.
    
        //Note: I'm assuming Session["ProductID"] should never be null.
    
        if (currentProductID == null)
        {
            //Loading page for the first time.
            currentProductID = (string)Session["ProductID"];
        }
        else if (currentProductID != Session["ProductID"])
        {
            //ProductID has changed since the page was first loaded, so react accordingly. 
            //You can use the original ProductID from the first load, or reset it to match the one in the Session.
            //If you use the earlier one, you may or may not want to reset the one in Session to match.
        }
    }
    

    In the above code, note that changes to the ViewState (including the value of a Hidden control) will only take effect on the next PostBack. On a refresh, they’ll revert to their most recent value. In my case, that was what I wanted, but it sounds like it’s not quite right for your situation. Still, that information could be useful to you, depending on how you implement this.

    I’ve left out a discussion of comparing currentProductID to Session[PageID.Value + "ProductID"], since I’ve already posted a lot of code, and I don’t know the details of what you’re trying to do. But there are various ways you can use Session, ViewState, and the QueryString to glean information about the state and history of the page.

    Hopefully that should give you the general idea. Let me know if that’s not enough to get you going.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.