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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:57:38+00:00 2026-05-11T00:57:38+00:00

I’m finding that hitting the Refresh button on my browser will temporarily screw up

  • 0

I’m finding that hitting the ‘Refresh’ button on my browser will temporarily screw up the ViewState for controls inside an UpdatePanel.

Here’s my situation : I made a custom WebControl that stores values in the ViewState. I put this control inside an UpdatePanel. When I hit the ‘refresh’ button on my browser, it will temporarily wipe out the values in ViewState. However, on the next postback, the values that were in the ViewState before I hit ‘refresh’ magically reappear.

This behavior screws up my webcontrol. After I hit ‘refresh,’ the control is returned to its initial state, since the ViewState is empty and IsPostBack is set to false. However, when I click on one of the postback controls within my WebControl, the WebControl will reload with the same values that were in ViewState before I hit ‘refresh.’

Strangely, this only happens when I’m using AJAX. When my control is outside of an UpdatePanel, Firefox gives me it’s standard message, ‘To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier (Resend) (Cancel).’ This is fine, because at least the behavior is consistent. However, I absolutely must use AJAX for this project.

So this is what I would like to do – I want to make the ‘refresh’ behavior consistent. It would be best if hitting ‘refresh’ didn’t affect the ViewState at all. But if it has to wipe out the ViewState, that’s fine, as long as the ViewState STAYS wiped out. None of this stuff with values disappearing and reappearing.

Oh yeah, and here’s my example code :

using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq;  namespace TestControls {     public class TestControl : WebControl     {         int _clickCount;         bool _mustUpdate;          protected override void LoadViewState(object savedState)         {             base.LoadViewState(savedState);              _clickCount = ((int)ViewState['clickCount']);             _mustUpdate = ((bool)ViewState['mustUpdate']);         }          protected override void OnLoad(EventArgs e)         {             base.OnLoad(e);              Controls.Clear();             ControlCreator();         }          private void ControlCreator()         {             Label tempLabel = new Label();             LiteralControl tempLiteral = new LiteralControl('<br/><br/>');             LinkButton tempLink = new LinkButton();              tempLink.ID = 'testLink';             tempLink.Text = 'Click me!';             tempLink.Click += new EventHandler(tempLink_Click);              tempLabel.ID = 'testLabel';             tempLabel.Text = _clickCount.ToString();              Controls.Add(tempLabel);             Controls.Add(tempLiteral);             Controls.Add(tempLink);         }          void tempLink_Click(object sender, EventArgs e)         {             _clickCount++;             _mustUpdate = true;         }          protected override void OnPreRender(EventArgs e)         {             base.OnPreRender(e);              if (_mustUpdate)             {                 Controls.Clear();                 ControlCreator();                  _mustUpdate = false;             }         }          protected override object SaveViewState()         {             ViewState['clickCount'] = _clickCount;             ViewState['mustUpdate'] = _mustUpdate;              return base.SaveViewState();         }     } } 
  • 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. 2026-05-11T00:57:39+00:00Added an answer on May 11, 2026 at 12:57 am

    I just re-read your question and realised I missed something…

    You are hitting the browsers refresh button!

    Is this a problem? YES!

    What happens when you hit the refresh button on the browser? It refreshes the current page. If there was a postback, it will resend the post data.

    The AJAX callback may update the ViewState as far as the page is concerned but hitting the browser refresh button will re-post the old ViewState.

    There is a wealth is discussion on the matter which you can Google.

    One very simple idea is to perhaps store the information in Session state instead perhaps. That too also can have its own issue too of course. But it may achieve your immediate goal.

    A tip for wiping the history of a postback (to prevent the re-post) is to redirect back to the same page again.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post

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.