Force refresh after postback
Force refresh after postback
Force refresh after postback
Force refresh after postback
Force refresh after postback
Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback
Force refresh after postback Force refresh after postback
Force refresh after postback
Go Back  Xtreme Visual Basic Talk > > > Force refresh after postback


Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2008, 11:40 AM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default Force refresh after postback


Is there a way to force a page-refresh after a postback?

During a button click postback, controls are dynamically added to the page. But for some odd reason the page isn't drawn properly. It isn't until a manual page-refresh, are the page controls functioning properly.
So, I'm thinking a forced page-refresh after postback. Is this possible? If so, how do I do it?

Thanks to all for their help.
Reply With Quote
  #2  
Old 05-13-2008, 12:05 PM
MKoslof's Avatar
MKoslofForce refresh after postback MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

If you aren't using AJAX or some asyncronous type processing you have a few options, but it depends what you want to do.

You can set the page to do no caching at all, or set it to no-cache, take a gander at the System.Web.HttpCachePolicy class.

Code:
 '***in page load events you can set it programmatically such as

 Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
 Response.Cache.SetCacheability(HttpCacheability.NoCache)
 Response.Cache.SetNoStore()

'***via page deritives, etc
<% 
    Response.ExpiresAbsolute = #TheDateTime# 
    Response.AddHeader "pragma", "no-cache" 
    Response.AddHeader "cache-control", "private, no-cache, must-revalidate" 
%>
But I really don't recommend this approach. This is typically a good solution if you want to kill the ability to have a history of authenticated pages, using the back button after logging out (and can't back boor in again). Trying to use these settings to force a "fresh" page pull after postback isn't going to be reliable or a good idea in my opinion.

You could always response.redirect("page",false) back to yourself, that is the old clunky stand by.

Another solution could be a javascript solution where you use an IFrame and set the src property and use the Page.RegisterStartupScript method to invoke your javascript:

Code:
<script language="javascript" type="text/javascript">
    function changeURL(url) 
    { 
        document.getElementById("iFrame").src=url; 
     } 
    </script>
Or have your button event register a start up script that simply invokes window.location.reload(); or the from the client, instruct it to reload the page, etc. That is probably your most straight forward and cleanest solution, since you isloate this behavior to a specific control event registering the start up script and invoking it, etc.

There are ways to refresh the page at given intervals server side by adding response headers, but that means you are refreshing every x number of seconds, which probably isn't what you want to do
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown

Last edited by MKoslof; 05-13-2008 at 12:11 PM.
Reply With Quote
  #3  
Old 05-13-2008, 12:51 PM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default

MKoslof,

Thanks soooo much for your help. I was using AJAX but couldn't seem to get it to work. After removing the AJAX method, I used the response.redirect(".") method and now it works exactly how I want it!

Thanks again for all your help!
Reply With Quote
  #4  
Old 05-13-2008, 12:54 PM
MKoslof's Avatar
MKoslofForce refresh after postback MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

No problem, good luck
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Force refresh after postback
Force refresh after postback
Force refresh after postback Force refresh after postback
Force refresh after postback
Force refresh after postback
Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback Force refresh after postback
Force refresh after postback
Force refresh after postback
 
Force refresh after postback
Force refresh after postback
 
-->