Make controls invisible even when back button pressed.

GregD

Newcomer
Joined
Jun 26, 2004
Messages
15
Hi,

On every page on my site i plan on having a username/password textbox and a submit button.

Once the user has logged in im hiding these controls and replacing them with a logout button. Im doing all this with the .visible method.

This works to a point but lets say ive browsed the website and ive decided to login after the third page. If i press the back button i have to refresh the page before the controls become invisible.

Is there a way of making the page not cache certain user controls ? Could i give them their new invisible status with viewstate or postback maybe?

So far ive only found Response.CacheControl = "no-cache"

But then users need to refresh the whole page.

Any suggestions would be appreciated.
 
A user can never expect to get new results (non-cached) when they hit the back button, I wouldn't break my head over it.
 
Ive seen it done in PHP.... over at forums.aspfree.com (no advertising intended) ;)

Even when I press back it realises im logged in. I know this is .NET but come on .NET can do tons more than php surely :)
 
Solved this myself after reading up on cacheing and user controls.

For anyone interested:

Created a new user control and put the following in the page_load of it...

Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires (DateTime.UtcNow)
Response.Cache.SetNoStore()
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)

So basically only the user control is being reloaded rather than the whole page.

Thanks for your suggestion anyway.
 
Last edited:
Robby said:
Good tip, I have never needed it but I can see it coming in handy, thanks.

The only drawback ive noticed is if you go back a few pages sometimes the button events no longer work. As such I have no idea why maybe because the events are no longer cached?

EDIT: Like the dumb person i am I forgot i had <%@ OutputCache Duration="1" %> at the top of my user control... so sometimes the user control would load fine... but since the page took longer than 1 second to load sometimes it just wouldn't appear at all lol!
 
Last edited:
Thanks Greg; I'll file that in long term memory; I'm sure I'll use that at some point! :D
 
Im currently working on a portal so I need to always have the current login state displayed because you can login on any page.

Another great thing to check out is smart navigation.

Try inserting it into your page directive:

<%@ Page Language="VB" SmartNavigation = "true"%>

From the documentation:

"Smart navigation is an ASP.NET feature that is supported in Internet Explorer 5.5 and later browsers. It allows a page to be refreshed while maintaining scroll position and element focus between navigations, causing only a single page to be stored in the browser's history, and without the common flicker associated with refreshing a Web page. Smart navigation is best used with ASP.NET pages that require frequent postbacks but with visual content that does not change dramatically on return. Consider this carefully when deciding whether to set this attribute to true."

This seems like a cool feature shame its only for IE :)
 
Back
Top