Is there an easy way to manually force the content page to postback or refresh from the master page without using an updatepanel?
2 Answers
If you are using jQuery or open to it, you can use a JavaScript timer to trigger the refresh and use jQuery's Ajax support to perform the actual refresh.
UPDATE
To address your comment about using the code-behind to do the refresh.
Once the server-side code runs, it returns HTML to the browser. The browser then renders that HTML. The server has absolutely no way to change the HTML code on its own after the code has been delivered to the browser. Only the browser can do that, by reaching out to the server (or potentially a different server) and requesting new data and changing the HTML itself in response to that request. The most common way to do that is with an Ajax call, though there are other technologies like Web Sockets that can accomplish similar things.
-
I'd rather not depend on a timer to refresh the content page a single time. Is it not possible to call the content page's Load function straight from the code-behind in the master page? – tareqx3 Oct 04 '12 at 17:47
-
You need to use JavaScript to refresh just part of the page, and the only mechanism I know of is to use a timer. Updated my answer to address code-behind calling the page's Load function. – Eric J. Oct 04 '12 at 19:27
-
Is there a way to do Web Sockets from a browser? I though Web Sockets required a plugin. – Trisped Oct 04 '12 at 22:16
-
Some of the newer browsers support Web Sockets natively, others need a plugin.http://en.wikipedia.org/wiki/WebSocket#Browser_support – Eric J. Oct 04 '12 at 22:19
It is not possible to communicate from the server to the browser without first getting a request from the browser. At the very least you will need a browser side timer which connects to the server.
Taking into account your comment to Eric J.'s answer, you could use an Ajax request to see if a refresh is needed, then process the response and act accordingly. If you are willing to use jQuery then his answer is correct.
If this does not answer your question then please give us the context of the problem you are trying to solve. Why does the server need to tell the browser to refresh? Why cannot the browser check ever 30 seconds to see if a refresh is needed?

- 5,705
- 2
- 45
- 58