SetRefresh Method for ASP.NET web pages to support postback.

I've read Willem's Blog post Auto-refreshing ASP.NET web pages  and desided to post my helper function SetRefresh(Page page,int nDelaySec) that is similar to suggested by Willem's third method, but supports postbacks. It's important to keep values, entered by the user before refresh.

            public static void SetRefresh(Page  page,int nDelaySec)

            { // from http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/msg/ffec2cc7c4836ed6?hl=en&

 

                  //NOTE: Often the __doPostBack function is inserted into your page by .NET. If not, put the code in manually, or add a dummy LinkButton and set it's style to be "display:none".

                  //     from http://www.codeproject.com/aspnet/OneTimeClickableButton.asp?msg=1185901

                  //window.Form1.submit();

                  int nMilliSec=nDelaySec*1000;

                  StringBuilder sb = new StringBuilder();

                  sb.Append("setTimeout(myRefresh,"+ nMilliSec.ToString()+ ");");

                  sb.Append( @" function myRefresh()

                        {

                         __doPostBack(document.forms[0].id,'');

                        } ");

                  page.RegisterClientScriptBlock("SetRefresh", JScript(sb.ToString()));

            }

The function included in My JScriptHelper class

posted @ Monday, October 31, 2005 6:44 AM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345