title: SignalR in ASP.NET WebForms
body: <p>In one of my projects I need to use SignalR library. So I decided to create one simple app to check how it works. I created this app based on a few tutorials which show how to write chat room.<br>
  The only difference is that my project is WebForms and I also use ASP.NET controls in it.</p>
  
  <p>This is what I've done so far:</p>
  
  <ol>
  <li><p>I installed <code>SignalR</code></p></li>
  <li><p>I created <code>ChatHub</code> file:</p></li>
  </ol>
  
  <p>ChatHub.cs</p>
  
  <pre><code>using System;
  
  using System.Collections.Generic;
  
  using System.Linq;
  
  using System.Web;
  
  using Microsoft.AspNet.SignalR;
  
  using Microsoft.AspNet.SignalR.Hubs;    
  namespace SignalRTest
  {
  
      public class ChatHub : Hub
      {
          public void sendMessage(string msg)
          {
              Clients.All.addMessage(msg);
          }
      }
  }
  </code></pre>
  
  <ol start="3">
  <li>In Default.aspx page:</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;script src="Scripts/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
      &lt;script src="Scripts/jquery.signalR-2.2.0.min.js"&gt;&lt;/script&gt;
      &lt;script src="/signalr/hubs"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
          $(function () {
              var chat = $.connection.chatHub;
  
              chat.client.addMessage = function (msg) {
                  $('#chat_list').append("&lt;li&gt;" + msg + "&lt;/li&gt;");
              };
  
              $.connection.hub.start().done(function () {
                  $('#Button1').click(function () {
                      chat.server.sendMessage($('#TextBox1').val());
                  });
              });
          });
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form id="form1" runat="server"&gt;
              &lt;div&gt;
                  &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:Button ID="Button1" runat="server" Text="Send" /&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;ul id="chat_list"&gt;
  
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <ol start="4">
  <li>Startup file:</li>
  </ol>
  
  <p>Startup.cs</p>
  
  <pre><code>using Microsoft.Owin;
  using Owin;
  
  [assembly: OwinStartup(typeof(SignalRTest.Startup))]
  namespace SignalRTest
  {
      public partial class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              app.MapSignalR();
          }
      }
  }
  </code></pre>
  
  <p>I set up breakpoints and clicking on Send button fires sendMessage method on server and also addMessage JS function on clients side. But here is the problem:</p>
  
  <p>When I send something to other user he can see that message in <code>&lt;ul&gt;&lt;/ul&gt;</code> element. But not me. Then when he sends me response I can see it but his list gets cleared.</p>
  
  <p>Can it be caused by using ASP controls?<br>
  I'm not sure if I get references to these controls in best way.</p>
  
  <p>PS. Sorry for bad formatting but I can't handle C# code.</p>