Re: ASP.NET Question

From: Jeffrey A. Voigt (voigt.jeffrey_at_myfloridahouse.com)
Date: 04/12/04


Date: Mon, 12 Apr 2004 14:29:53 -0400

We have something similar on our site. check out
www.myfloridahouse.com/session_live_preview.aspx. We have to update
information to the user every 60 seconds so the user knows if the House is
dicussing another bill and/or amendment. We achived this by setting an
autopost back every 60 seconds with the following code:

private void RegisterRefreshScript()
{
 // register a script to auto post back every so many seconds
 // NOTE: Setting a meta tag to refresh will not do a (POST BACK)
 int refreshRate =
Convert.ToInt32(ConfigurationSettings.AppSettings["SessionLiveRefreshRate"])
;
 StringBuilder scriptBlock = new StringBuilder();
 scriptBlock.Append( "<script>" );
 scriptBlock.Append( "function sessionLive_autoPostBack() ");
 scriptBlock.Append( "{ " );
 scriptBlock.Append( " __doPostBack('lnkPostBack','');");
 scriptBlock.Append( "} " );
 scriptBlock.Append( "window.setInterval( 'sessionLive_autoPostBack()', ");
 scriptBlock.Append( refreshRate.ToString() );
 scriptBlock.Append( "); ");
 scriptBlock.Append( "</script>" );
 RegisterStartupScript( "autoPostBack", scriptBlock.ToString() );
}

If you call this function each time there is a postback, you can be assurred
that the brower will post back to the server every so many seconds. Don't
let this confuse you, the lnkPostBack is just a server side link button
declare on the ASPX page like so:

<asp:LinkButton ID="lnkPostBack" Runat="server"></asp:LinkButton>

What is nice is that that when the post back happens it will call the
lnkPostBack_Click event (so long as you have an event for it set up) so you
know the difference between the user clicking the refresh button, other
buttons that may cause a post back, and the registered script block that was
added.

Let me know if this helps you out!

Thanks,

"Shreyash Patel" <anonymous@discussions.microsoft.com> wrote in message
news:0B7328D7-3170-46CB-851F-735395CED403@microsoft.com...
> How do I make PostBack Call from the Server so that I can update something
on the client web browser? The Client just has the page open theres is no
event from the Client. But I want to push something from the server so that
the client webpage reloads with the new information. Code Sample Please?
>
> Shreyash