Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to update my gridview in other browser when i upload file in current browser..i use signalR to implement that.. here is my source code.. here is my NotificationHub.vb

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


Here is Startup.vb

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


in home.aspx

Java
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 ($(<code></code>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);
        })

and the last in home.aspx.vb (i write this code after upload's code)

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()


i hope you can help me everyone.. thanks :)
Posted
Updated 14-Jun-14 4:48am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900