Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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 :)

Posted (edited)

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.

Edited by GregD
Posted (edited)
Good tip' date=' I have never needed it but I can see it coming in handy, thanks.[/quote']

 

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!

Edited by GregD
Posted

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 :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...