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

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Monday, October 31, 2005 6:44 AM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910