Is it possible, using asp.net and vb.net as the code behind, to update an UpdatePanel on a System.Timers.Timer elapsed event? I know a timer control is available, but please help me to do this with the Systems.Timer.Timer - I have reason to use it this way.
是否可以使用asp.net和vb.net作为代码,更新System.Timers.Timer已事件事件上的UpdatePanel?我知道有一个计时器控件可用,但是请帮我用Systems.Timer.Timer帮我做 - 我有理由这样使用它。
Every time the subroutine that handles my timer's elapsed event is called, I have a literal whose text I update. After I update the text, I call update() on my UpdatePanel. Nothing happens. I know there are ways to do this with Javascript on the client side, but if at all possible I want to stay away from that and stay server side, which I feel is what the Ajax UpdatePanel is trying to do for me anyway. I feel like the UpdatePanel should do exactly what I need, updating just a small portion of my page, in this case where my literal is stored. Thank you so much in advance.
每次调用处理我的计时器的已用事件的子程序时,我都有一个文本我更新的文字。更新文本后,我在UpdatePanel上调用update()。什么都没发生。我知道有很多方法可以在客户端使用Javascript来实现这一点,但是如果可能的话我想远离那个并保持服务器端,我觉得这就是Ajax UpdatePanel试图为我做的事情。我觉得UpdatePanel应该完全符合我的需要,只更新我的页面的一小部分,在这种情况下我的文字存储。非常感谢你提前。
Here is part of my markup:
这是我的标记的一部分:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Literal ID="timerLit" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
And here is my vb:
这是我的vb:
Protected Sub onTimerElapsed(source As Object, e As ElapsedEventArgs)
timerLit.Text = "Hello"
UpdatePanel1.update()
End Sub
I have tried many things. I know that my onTimerElapsed subroutine is called, and I know that the literal gets filled with the correct text. The update() just doesn't seem to do anything. Thanks again!
我尝试了很多东西。我知道我的onTimerElapsed子程序被调用,我知道文字填充了正确的文本。 update()似乎没有做任何事情。再次感谢!
2 个解决方案
#1
1
The UpdatePanel only works from client to server. The scenario you are describing is not possible (at least not with the techniques you're using). That is because there's really no way for the server to connect to the client.
UpdatePanel仅适用于客户端到服务器。您描述的场景是不可能的(至少不是您正在使用的技术)。那是因为服务器真的没办法连接到客户端。
There are two possibilities:
有两种可能性:
- Either do it from client to server (which you discarded)
- 从客户端到服务器(您丢弃了它)
- Use a framework like SignalR if you really want to push it from the server-side.
- 如果你真的想从服务器端推送它,请使用SignalR这样的框架。
SignalR implements the client-side and server-side plumbing for you and uses the best technique available in the current browser.
SignalR为您实现客户端和服务器端管道,并使用当前浏览器中可用的最佳技术。
Here you can find more information on SignalR: http://signalr.net/
在这里您可以找到有关SignalR的更多信息:http://signalr.net/
#2
0
Rather than trying to go Server -> Client go from Client -> Server.
而不是试图去服务器 - >客户端从客户端 - >服务器。
So in javascript create a timer that will call your code-behind every XXX seconds.
所以在javascript中创建一个计时器,每隔XXX秒调用一次代码隐藏。
Something like this.
像这样的东西。
var myTimer = setInterval(myMethod, 5000);
function myMethod( )
{
//this will repeat every 5 seconds
//you can reset counter here
}
you can clear the timer and stop it calling your method by calling
你可以清除计时器并通过调用停止它调用你的方法
clearInterval(myTimer);
#1
1
The UpdatePanel only works from client to server. The scenario you are describing is not possible (at least not with the techniques you're using). That is because there's really no way for the server to connect to the client.
UpdatePanel仅适用于客户端到服务器。您描述的场景是不可能的(至少不是您正在使用的技术)。那是因为服务器真的没办法连接到客户端。
There are two possibilities:
有两种可能性:
- Either do it from client to server (which you discarded)
- 从客户端到服务器(您丢弃了它)
- Use a framework like SignalR if you really want to push it from the server-side.
- 如果你真的想从服务器端推送它,请使用SignalR这样的框架。
SignalR implements the client-side and server-side plumbing for you and uses the best technique available in the current browser.
SignalR为您实现客户端和服务器端管道,并使用当前浏览器中可用的最佳技术。
Here you can find more information on SignalR: http://signalr.net/
在这里您可以找到有关SignalR的更多信息:http://signalr.net/
#2
0
Rather than trying to go Server -> Client go from Client -> Server.
而不是试图去服务器 - >客户端从客户端 - >服务器。
So in javascript create a timer that will call your code-behind every XXX seconds.
所以在javascript中创建一个计时器,每隔XXX秒调用一次代码隐藏。
Something like this.
像这样的东西。
var myTimer = setInterval(myMethod, 5000);
function myMethod( )
{
//this will repeat every 5 seconds
//you can reset counter here
}
you can clear the timer and stop it calling your method by calling
你可以清除计时器并通过调用停止它调用你的方法
clearInterval(myTimer);