title: Asp.net idea on how chat box logic works?
body: <p>currently I have a chat box on asp.net webform</p>
  
  <p>What I am using now is scriptmanager 
  Timer,  updatepanel, and trigger
  Updatepanel is set to conditional.
  Trigger set with timer I'd.</p>
  
  <p>Every few seconds.  The timer runs timer_tick and checks the sql database for new message and update the updatepanel. </p>
  
  <p>My problem is the updatepanel gets refreshed every few seconds regardless of if there is new messages.</p>
  
  <p>In the code behind, How do I make it only postback if a conditional is made.  Is it because my trigger is set to the timer?   I have tested it.  Even if the timer method is completely empty.  It still updates the updatepanel.</p>
  
  <p>Is there any way in the timer method to force no postback?</p>
  
  <p>Is it possible to make a client side thread to check the chat message database then update the updatepanel if a conditional is made? </p>
  
  <p>Thanks.</p>
  
  <p>The problem is regardless if i put a conditional or not.. Timer1_Tick() always refreshes the updatepanel.
  In the code behind</p>
  
  <pre><code>    protected void Timer1_Tick(object sender, EventArgs e)
  {
  
      if (All_Panel.Enabled)
      {
          SQL DB = new SQL();
          if (DB.IsCustomerOnline())
          {
              SessionID = DB.GetSessionID();
              if (SessionID.CompareTo("") != 0)
              {
                  if (!C_BT_Message.Enabled)
                  {
                      DB.AddNewMessage(Request.UserHostAddress, "Connected Customer: " + SessionID, SessionID, "Admin");
                      C_BT_Message.Enabled = true;
                  }
              }
              else
              {
                  C_BT_Message.Enabled = false;
              }
          }
          List&lt;string&gt; li = DB.GetMessages(DB.GetSessionID());
  
          if (TotalRow != li.Count &amp;&amp; li.Count &gt; 0)
          {
              try
              {
                  foreach (string s in li)
                  {
                      // CreateDiv(s, "ForUser");
  
                      CreateDiv(GetDate(s) + "&lt;br /&gt;" + GetMessage(s), GetIdentity(s).CompareTo("Customer") == 0 ? "ForUser" : "ForAdmin");
                  }
              }
              catch (Exception err)
              {
  
              }
          }
          TotalRow = li.Count;
      }
  
  }
  </code></pre>
  
  <p>Below is the aspx.  </p>
  
  <pre><code>          &lt;asp:Timer ID="Timer1" runat="server" Interval="3000"  OnTick="Timer1_Tick"&gt;&lt;/asp:Timer&gt;
  &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt;
       &lt;Triggers&gt;
       &lt;asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /&gt;
       &lt;/Triggers&gt;
        &lt;ContentTemplate&gt;
         &lt;div id="chat_box" runat="server" class="C_chat"&gt;
          &lt;div id="C_ChatAdmin" runat="server" class ="C_ChatMessage"&gt;
  
          &lt;/div&gt;
         &lt;/div&gt;
        &lt;/ContentTemplate&gt;
  
   &lt;/asp:UpdatePanel&gt;
  </code></pre>