title: Update textbox value in asp page through WCF service from console application
body: <p>I have a c# console application scheduled to run on a Win 2003 server reading values such as disk space, cpu usage etc.</p>
  
  <p>Now I want to display these values online or real-time, on an aspx page.</p>
  
  <p>This my (non-working) attempt so far:</p>
  
  <p>The WCF service:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  
  namespace ServerMonitoring
  {
      public class Service1 : IService1
      {
  
          public void InsertDataValues(DataValues server)
          {
              FreeDiskSpace = server.FreeDiskSpace;
              Data.FreeDiskSpace = FreeDiskSpace;
          }
  
          [DataMember]
          public decimal FreeDiskSpace
          {
              get { return Data.FreeDiskSpace; }
              set { Data.FreeDiskSpace = value; }
          }
  
      }
  }
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  
  namespace ServerMonitoring
  {
      [ServiceContract]
      public interface IService1
      {        
          [OperationContract]
          void InsertDataValues(DataValues server);
      }
  
      [DataContract]
      public class DataValues
      {
          [DataMember]
          public decimal FreeDiskSpace;
          /*
          [DataMember]
          public decimal TotalDiskSpace;
          */
      }
  }
  </code></pre>
  
  <p>Try to update textbox from Code behind:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace ServerMonitoring
  {
      public partial class _Default : System.Web.UI.Page
      {
         protected void Page_Load(object sender, EventArgs e)
         {
          TextBox1.Attributes.Add("onchange", "DefaultValue();");
          HiddenFieldFreeDiskSpace.Value = Data.FreeDiskSpace.ToString();
  
          }
      }
  } 
  </code></pre>
  
  <p>Default.aspx:</p>
  
  <pre><code>&lt;%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"                 
  AutoEventWireup="true"
  CodeBehind="Default.aspx.cs" Inherits="ServerMonitoring._Default" %&gt;
  
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="head"&gt;
      &lt;script type="text/javascript"&gt;
          function DefaultValue() {
              var data = $('#&lt;%=HiddenFieldFreeDiskSpace.ClientID%&gt;').val(); 
              var txt1 = document.getElementById("TextBox1");
              txt1.setAttribute("value", data);
          }
      &lt;/script&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="BodyContent" runat="server"     ContentPlaceHolderID="ContentPlaceHolder1"&gt;
      &lt;div class="extra-wide-column"&gt;
          &lt;h2&gt;
              FIC Server Monitoring Services
          &lt;/h2&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;h3&gt;System&lt;/h3&gt;
          &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
              &lt;ContentTemplate&gt;
                 &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
                 &lt;asp:HiddenField runat="server" ID="HiddenFieldFreeDiskSpace" /&gt;
              &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;
      &lt;/div&gt;
  &lt;/asp:Content&gt; 
  </code></pre>
  
  <p>The value to be written to the textbox is coming from my console app with a reference to my WCF service</p>
  
  <pre><code>static void UpdateList(string columnName, decimal diskSpaceValue)
      {
          Service1 serv = new Service1();
          DataValues dv = new DataValues();
          dv.FreeDiskSpace = diskSpaceValue;
          serv.InsertDataValues(dv);
  
      } 
  </code></pre>
  
  <p>However, the value is not sent to the asp page</p>
  
  <p>BR,
  Peer</p>