从Master刷新内容页,不需要更新面板

时间:2021-10-29 21:11:53

Is there an easy way to manually force the content page to postback or refresh from the master page without using an updatepanel?

是否有一种简单的方法可以在不使用updatepanel的情况下手动强制内容页进行回发或从母版页进行刷新?

2 个解决方案

#1


1  

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.

如果您正在使用jQuery或打开它,您可以使用JavaScript计时器触发刷新,并使用jQuery的Ajax支持来执行实际的刷新。

Jquery/Ajax call with timer

Jquery / Ajax调用计时器

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.

服务器端代码运行后,将HTML返回给浏览器。然后浏览器呈现该HTML。在将代码交付给浏览器后,服务器完全无法自己更改HTML代码。只有浏览器才能做到这一点,通过向服务器(或可能是另一个服务器)发出请求,并请求新的数据,并根据该请求更改HTML本身。最常见的方法是使用Ajax调用,尽管还有其他技术,如Web Sockets,可以完成类似的事情。

#2


0  

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.

考虑到你对Eric J的评论。您可以使用Ajax请求查看是否需要刷新,然后处理响应并相应地执行。如果您愿意使用jQuery,那么他的答案是正确的。

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?

如果这不能回答你的问题,那么请给我们你要解决的问题的背景。为什么服务器需要告诉浏览器刷新?为什么浏览器不能在30秒内检查是否需要刷新?

#1


1  

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.

如果您正在使用jQuery或打开它,您可以使用JavaScript计时器触发刷新,并使用jQuery的Ajax支持来执行实际的刷新。

Jquery/Ajax call with timer

Jquery / Ajax调用计时器

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.

服务器端代码运行后,将HTML返回给浏览器。然后浏览器呈现该HTML。在将代码交付给浏览器后,服务器完全无法自己更改HTML代码。只有浏览器才能做到这一点,通过向服务器(或可能是另一个服务器)发出请求,并请求新的数据,并根据该请求更改HTML本身。最常见的方法是使用Ajax调用,尽管还有其他技术,如Web Sockets,可以完成类似的事情。

#2


0  

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.

考虑到你对Eric J的评论。您可以使用Ajax请求查看是否需要刷新,然后处理响应并相应地执行。如果您愿意使用jQuery,那么他的答案是正确的。

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?

如果这不能回答你的问题,那么请给我们你要解决的问题的背景。为什么服务器需要告诉浏览器刷新?为什么浏览器不能在30秒内检查是否需要刷新?