当我在当前浏览器中上传文件时,我想在其他浏览器中更新我的gridview ..我使用signalR来实现它.. 这是我的源代码..这是我的NotificationHub.vb
Imports System.Web
Imports Microsoft.AspNet.SignalR
Namespace SignalRChat
Public Class NotificationHub
Inherits Hub
Public Sub Send(name As String, message As String)
' Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message)
End Sub
End Class
End Namespace
这是 Startup.vb
Imports Microsoft.AspNet.SignalR
Imports Microsoft.Owin.Security
Imports Owin
Imports Microsoft.Owin
'add the attribute here
<Assembly: OwinStartup(GetType(SignalRTutorials.Startup))>
Namespace SignalRTutorials
Public Class Startup
Public Sub Configuration(app As IAppBuilder)
'app.MapSignalR()
Dim hubConfiguration = New HubConfiguration()
hubConfiguration.EnableDetailedErrors = True
hubConfiguration.EnableJavaScriptProxies = True
app.MapSignalR("/signalr", hubConfiguration)
End Sub
End Class
End Namespace
home.aspx 中的
var NotificationHub = $.connection.NotificationHub;
NotificationHub.client.refresh = function (stock) {
//Just some tracing purposes
//console.log('Refresh method triggered successfully!');
//console.log(stock);
//Refresh the gridview with latest data
$("#Gridview1").each(function (i) {
if ($(this)[0].id == stock.ID) {
//highlight the row that has data changed then slowly fade
$(this).attr('style', 'background-color: yellow;');
$(this).animate({ backgroundColor: 'white' }, 3000);
}
});
};
$.connection.hub.start().done(function () {
//Just to trace whether your browser successfully connected to SignalR hub
console.log('Connected to SignalR hub, connection ID = ' + $.connection.hub.id);
})
和home.aspx.vb中的最后一个(我在上传代码后编写此代码)
Dim context = GlobalHost.ConnectionManager.GetHubContext(Of NotificationHub)()
Dim aTimer = New System.Timers.Timer(1000)
aTimer.Interval = 3000
aTimer.Enabled = True
context.Clients.All.refresh()
我希望你能帮助我... 谢谢:))