Note that there are some explanatory texts on larger screens.

plurals
  1. POSignalR realtime notification not persisting on the client
    primarykey
    data
    text
    <p>I am trying to implement a feature where user uploads a file, server processes the file and and displays realtime notification to the client about the status of processing e.g. validated, imported etc. There are examples where the client sends data from textboxes to the javascript proxy. </p> <pre><code> $("#btnTest").click(function () { myHub.testMethodOnHub($("#txtEmail").val()); }); </code></pre> <p>I need to send binary data to the server via signalR so that server can process that data and notify client using SignalR.</p> <p>EDIT :- I was able to call a JS method from aspx.cs to set the status client side - realtime. However, the message disappears after page finishes loading.</p> <p>What I have tried :-</p> <p><strong>ASPX :-</strong></p> <pre><code>&lt;%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MultipleStepsUsingSignalR._Default" %&gt; &lt;script src="Scripts/jquery-1.6.4.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Scripts/json2.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Scripts/jquery.signalR-0.5.2.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="signalr/hubs" type="text/javascript"&gt;&lt;/script&gt; &lt;body&gt; &lt;form id="Form1" runat="server"&gt; &lt;p&gt; &lt;asp:FileUpload ID="fileUpload" runat="server" /&gt; &lt;asp:Button ID="btnProcessFile" runat="server" Text="Process File" onclick="btnProcessFile_Click" /&gt; &lt;asp:HiddenField ID="hdnConnectionId" runat="server"/&gt; &lt;%--&lt;asp:Label Text="" ID="lblStatus" runat="server" /&gt;--%&gt; &lt;span id="lblStatus"&gt;&lt;/span&gt; &lt;/p&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { var multipleStepsHub = $.connection.multipleStepsHub; multipleStepsHub.MethodInJavascript = function (status) { $('#lblStatus').append(status); }; $.connection.hub.start().done(function () { $('#&lt;%= hdnConnectionId.ClientID %&gt;').val($.connection.hub.id); alert($('#lblStatus').text()); }); }); &lt;/script&gt; &lt;/body&gt; </code></pre> <p><strong>Hub</strong></p> <pre><code>[HubName("multipleStepsHub")] public class MultipleStepsHub : Hub { public void ExecuteMultipleSteps(string status) { } } </code></pre> <p><strong>Code-behind for aspx</strong></p> <pre><code> protected void btnProcessFile_Click(object sender, EventArgs e) { string connectionId = hdnConnectionId.Value; var context = GlobalHost.ConnectionManager.GetHubContext&lt;MultipleStepsHub&gt;(); byte[] dataFromPostedFile = GetDataFromUploadedFile(fileUpload.PostedFile.InputStream); context.Clients[connectionId].MethodInJavascript("&lt;br&gt;File updloaded."); Thread.Sleep(5000); context.Clients[connectionId].MethodInJavascript("&lt;br&gt;Processing step1"); Thread.Sleep(5000); context.Clients[connectionId].MethodInJavascript("&lt;br&gt;Processing step2"); Thread.Sleep(5000); context.Clients[connectionId].MethodInJavascript("&lt;br&gt;Processing step3"); } </code></pre> <p><strong>What do I expect :-</strong> Status text changing to "Processing step1" then "Processing step2" and then "Processing step3"</p> <p><strong>What is the result</strong> :-</p> <p>a) There is a change in the status periodically (after Thread.Sleep), however, when the page finishes, the status disappears. As you notice in the below, "Processing step1" and "Processing step2" do appear, but later disappear.</p> <p><img src="https://i.stack.imgur.com/qDEMy.gif" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload