开发者

How to completely refresh (ctrl+f5) a page using asp.net?

开发者 https://www.devze.com 2023-03-29 02:53 出处:网络
I am working with an asp.net (Dotnetnuke) project now. I need to change an image in a page dynamically. While clicking replace button (asp:Button), some times the image cannot replace dynamically on t

I am working with an asp.net (Dotnetnuke) project now. I need to change an image in a page dynamically. While clicking replace button (asp:Button), some times the image cannot replace dynamically on the page. While pressing c开发者_StackOverflow社区trl+F5, it will change. My question is, how to reload cache through C# code?

Another problem is that, sometimes I replace an image in a page by storing some values to database and press ctrl+F5 for making changes in the page, but while clicking ctrl+F5 there shows a dialog box with cancel or retry buttons (both on Firefox and IE). While clicking any one of them will store the same value to database. If we again refresh the page the value in the database is 3 times.


you cannot clear browser cache.the only idea is declare a session variable in c# code in page load and set its value is 1 at the very first time

if (!IsPostBack)
            {
Session["refresh"]="1"
}

you will need to set session variable in image upload button event Session["refresh"]="1" then create a refresh button .in the button event do the following thats all.after completeing your upload,click on the refresh button.then it work as ctrl+f5 button.if you not set the session value 0 in refresh button event the last event is again takesplace.if you enter a value in database,the same task takesplace if you not set session variable 0.

   if(Session["refresh"].ToString()=="1")
   {
      Response.Write("<script type='text/javascript'>locaton.reload()</script>");
      Session["refresh"]="0";
    }


JavaScript cannot access dumping the cache for you, sorry. C# runs of the server, not the client, so it can't help either.

If you want to break the cache for certain items in the page you can add a random parameter

<img src="a.gif?x=123456"> (I like to use a time-stamp)

Alternately, if this is for testing purposes, turn off the cache in your browser.


You can manipulate the cache charateristics of various portions of your web page by managing the user controls. Also check your page directives.

 <%@ OutputCache Duration="#ofseconds" Location="Any | Client | Downstream | Server | None" Shared="True | False" VaryByControl="controlname" VaryByCustom="browser | customstring" VaryByHeader="headers" VaryByParam="parametername" %>

The caching functionality of ASP.NET is pretty extensive. I would recommend you spend some time studying the application Directives; mainly Page and Control.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号