locked
dbnotification change udpated only on page refresh RRS feed

  • Question

  • User1182768036 posted

    Whenever db value got changed, page refresh is required...here is my piece of code..please suggest.

    public override Task OnConnected()
    {

    MessagesRepository mr = new MessagesRepository();
    ClientValue = Context.QueryString["Name"].ToString();
    // Clients.Client(ClientValue).updateMessages(mr.GetAllMessages());
    return base.OnConnected();
    }

    public override System.Threading.Tasks.Task OnDisconnected()
    {

    return base.OnDisconnected();
    }
    public void Hello()
    {
    Clients.All.hello();

    }

    [HubMethodName("sendMessages")]
    public static void SendMessages()
    {

    IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MessagesHub>();
    var config = new HubConfiguration {EnableDetailedErrors = true };
    //Console.WriteLine(HttpContext.Current.Session[Constants.UserName].ToString());
    // Clients.Client(Context.ConnectionId).addMessage(Name + ": " + Message)
    // Console.WriteLine(HttpContext.Current.User.Identity.Name.ToString());
    string connectionId = string.Empty;
    context.Clients.Client(ClientValue).updateMessages();
    }

    }

    Thursday, April 28, 2016 12:12 PM

Answers

  • User61956409 posted

    Hi skumarvs,

    Whenever db value got changed, page refresh is required...here is my piece of code..please suggest.

    Normally, we call client function from hub method when database updated, if you’d like to refresh your web page, you could try to modify your client function to reload the current page.

    yourhub.client.updateMessages = function () {
        //your code
        //broadcast dbnotification 
    
        if (confirm("database is updated, do you want to reload data?")) {
            window.location.reload(true);
        }
    }
    

    For more information about Location reload() method, please check this link.

    http://www.w3schools.com/jsref/met_loc_reload.asp

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 29, 2016 3:32 AM