title: ASP.NET Dynamic SignalR Hubs? groups?
body: <p>I have web controls (gauges) I create dynamically 1 to x (max 30) depending on the Job setup on page load. The SignalR Hub code is on a timer that fires every 20 seconds. This way my dynamic gauges get data <strong>every 30 seconds</strong>. I am setting the value for the control with a client javascript function guage.set_vale(). This function loops through every 30 seconds when the hub fires and sets the values.</p>
  
  <pre><code>   For i As Integer = 0 To 7
          Dim UserControl As WebUserControl1 = CType(Me.LoadControl("~/WebUserControl1.ascx"), WebUserControl1)
          UserControl.ID = "RG" &amp; (i)  ''1_RadGauge
  
          UserControl.ControlWidth = 9
          UserControl.setTankNumber = i + 20
          Me.Panel1.Controls.Add(UserControl)
  
      Next
  </code></pre>
  
  <p>Currently, all controls are getting data from the same single HUB. The data that feeds these controls is a SQL database on the server side. </p>
  
  <pre><code>SELECT top(1) * from zSignalR_DB_Test order by id desc
  </code></pre>
  
  <p>So all controls are showing the same data. 
  What I want to do is have each control show its data. So each control would be getting its own data from the database</p>
  
  <pre><code>    SELECT top(1) * from zSignalR_DB_Test WHERE ID = 'MyControlID' order by id desc
  </code></pre>
  
  <p>I have looked at SignalR Groups but have not seen how to do what I am trying to do. In this way, all I would need to do is associate the controlID with the data in the database.</p>
  
  <p>My questions are:</p>
  
  <p>Do I need a separate SignalR Hub for every control I create dynamically?</p>
  
  <p>Do I need to create those hubs dynamically?</p>
  
  <p>Is SignalR Groups the right way of doing this?</p>
  
  <p>If I am only updating every 30 seconds or a minute could I not just create a method that sends the ID back from the client and as I loop through each control in the client (maybe add a 1 second pause) send the ID a run a different SQL statement?</p>
  
  <p>Any thoughts or examples would be great.</p>
  
  <p>More code:</p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
    $(function() {
          var logger = $.connection.loghub;
          logger.client.logMessage = function(msg) { 
  
              var ajaxPanel = document.getElementById("Panel1");  
              for (var x = 0; x &lt; ajaxPanel.children.length; x=x+2) {  
  
                  if (msg &lt;=50){
                      var ImageElementGreen = ajaxPanel.children[x].children[0];
                      ImageElementGreen.style.visibility = 'visible'
                      var ImageElementRed = ajaxPanel.children[x].children[1];
                      ImageElementRed.style.visibility = 'hidden'
                  } else {
                      var ImageElementGreen = ajaxPanel.children[x].children[0];
                      ImageElementGreen.style.visibility = 'hidden'
                      var ImageElementRed = ajaxPanel.children[x].children[1];
                      ImageElementRed.style.visibility = 'visible'
                 }
  
                  var TBValueElement = ajaxPanel.children[x].children[3].children[0];
                  var TBValue = $find(TBValueElement.id);
                  TBValue.set_value(msg + "%");
  
                  var linearGaugeElement = ajaxPanel.children[x].children[4];
                  var linearGauge = $find(linearGaugeElement.id);                           
                  linearGauge.set_value(msg);  
              }
          };
          $.connection.hub.start();
      });     
  &lt;/script&gt;
  </code></pre>