Click here to Skip to main content
15,918,889 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i need a code that refresh the page just one time, i dont want it to read from cache.
i tried every case but they all refresh the page in an infinite loop.
is there a way to refresh it only once???
Posted

One of the ways i can think of right now is... using Javascript for it.
You would need to use setTimeout .

For setTimeout that fires after the specified delay, only once!:
http://www.howtocreate.co.uk/tutorials/javascript/timers[^]
 
Share this answer
 
v2
Do you want to refesh the page using javascript?? Your question is not clear to me.
 
Share this answer
 
any possible way javascript anything
i tried using setTimer, but the problem is it that i need it once the page is loaded and thats it.
 
Share this answer
 
your question is not clear also for me, i guess you should put !Page.IsPostBack on Page_Load. Please let us know.
based on CG's reply, your code should be like
protected override void OnPreRender(EventArgs e)
{
  image1.ImageUrl = "user1.jpg";
}
 
Share this answer
 
v2
I guess all you need to do, is add some code to the examples you found, to detect that the page has been refreshed once already, and thus not to write out the javascript that causes it to reload itself.

One way to do this, is to put a hidden field on your form in the aspx, and put a number in it ( such as 1 or 0 ), and increment the value in it every time it posts back. Then you can stop writing the code to refresh your page when the value gets to a certain number.

The question is clear, the people who don't think it was, should perhaps refrain from answering if they can't understand plain English.
 
Share this answer
 
here is my problem:
i have a web form that contains an image which is loaded from tha database according to the user id, when i open lets say the form for user_id:1 i get his image, but when i open the form for user_id:2 i get the last image i opened which is the image for user_id:1.
when i hit F5 the page refresh and the right image appears which is image for user_id:2.
so i need a code to do that for me.(refresh the page to get the right image from the database again not from the cache ).
 
Share this answer
 
OK, so you have several issues

1 - you keep pushing 'answer' to ask more questions, which makes it hard to answer you

2 - you asked a question in order to get help in working around a bug without really fixing it.

To refresh your page to fix a bug in your code is retarded. Surely no-one is paying for code that adheres to such low standards ?

Step through your code. Work out why it's doing this ( I'd say it's because you're binding your image in page load instead of page prerender, your event fires AFTER you load the image, so the ID gets updated too late ), and fix it. Buy a basic book on ASP.NET, especially read up on the page lifecycle, as it's clear you have no idea of the basics of the framework you're using.
 
Share this answer
 

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