Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a web page in which I use a couple of panels to control visibility of sections of the page. EnableViewstate is set to false in the page's master page.

If, on the first visit to the page, PanelA is visible and PanelB is hidden, then I swap this in a postback event, I get the expected result - i.e. PanelB is now the visible one. So far so good. However, if I now hit F5 to refresh the page, I find that PanelA remains hidden and PanelB remains visible.

Why doesn't the page go back to its initial default state? Even more puzzling, if I put a breakpoint in the Page_Load even, I find that, upon pressing F5, the Visible property is set as I would expect, back in the default state, with PanelA.Visible=true and PanelB.Visible=false. Yet PanelA remains hidden and PanelB still appears on the screen.

Does anyone have any idea what I'm missing?

Kind wishes ~ Patrick
Posted

1 solution

F5 (page refresh) from browsers are do full-post-back, means it's a new load of your page (and not a partial-post-back). So your page is rendered as it was it's first load A visible and B hidden!
If you want to store state between loads (I mean new an full loads) of your page ,you have to maintain that state - maybe using cookies...
 
Share this answer
 
Comments
Patrick Skelton 14-Jan-14 5:34am    
Hi,

Thank you for your answer.

Your answer confirms what I thought - that F5 is a full post-back; however, I seem to be seeing different behaviour to this. The state of the page is somehow being preserved during F5 without my using cookies or anything. What you describe in your answer is actually exactly what I want to happen. I just don't know why it isn't.

- Patrick
Kornfeld Eliyahu Peter 14-Jan-14 5:39am    
The state that you see form debugger is depend on which point of the page life cycle you stopped.
By default you may see the previous state because of view or control state stored in page but it will be discarded in later steps by the rendering engine...
Patrick Skelton 14-Jan-14 5:43am    
Ah... I have partly discovered the problem. When I hit F5, the visibility is set as I would expect (i.e. back to starting values) in Page_Load, but then the button-click event handler fires again, which changes the panel visibility. So the new question is: why is the event handler firing again on F5? Is that normal behaviour?
Kornfeld Eliyahu Peter 14-Jan-14 5:48am    
Not.
You may read this http://www.codeproject.com/Articles/10240/Detecting-Page-Refresh

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900