Refresh a webpage from the vb code

liunx

Guest
Any ideas how I'd do this? I need to change the number of seconds it takes for the page to refresh based on a certain condition so I can't use meta refresh.

Thanks!need to change the number of seconds it takes for the page to refresh based on a certain condition


embedded javascript from code-behind so you can control the certain amount of time to refreshHow might I go about doing that?I have not test my code, but the idea should be very obvious...
suppose you defineded a js function which is sitting in your aspx page:


<script language="JavaScript">
function doLoad(timer){
var sURL = unescape(window.location.pathname);
setTimeout( "refresh()", timer );

function refresh()
{
window.location.href = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/sURL;">http://www.webdeveloper.com/forum/archi ... .php/sURL;</a><!-- m -->
}//end refresh()
}//end timer
</script>


what it the function "doLoad" does, is to take a parameter, and refresh your window based on whatever you are going to passing in.

in your body tag, you want to call doLoad, so your page will start refresh itself...


<body onload="doLoad(<%# Timer %>);">


now, the expression <%# Timer %> is a single value data binding technique, you can trigger the value through code behind...

so in your code behind, you will have something alone the line with this:

private void Page_Load(object sender, EventArgs e){
public int Timer; <-- this is the same variable u use for databinding!
// do your logic here....
// when logic is done, databind the value with aspx page
this.DataBind();
}//end page_load


now whatever you've set for Timer, will pass to your body tag at ur aspx page. then body tag will start calling your javascript function and page will be start refreshing.

p.s: this method puts a lot of stress on your server, consider page is being request over and over and over again. That is including a lot of unwanted information such as HTTP header and stuff u won't need. I still recommand using AJAX to accomplish such a goal...
 
Back
Top