title: Display the current date in an ASP.NET label with C# and JS
body: <p>I'm trying to display the current date in an ASP.NET label using JavaScript and C#.  Here's what I have:</p>
  
  <p>C#:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "addScript", "GetDate()", true);
  }
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function GetDate() 
      {
          var dt = new Date();
          var element = document.getElementById("MainContent_FormView1_Label1");
  
          element.text = dt.toDateString();
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>ASP.NET:</p>
  
  <pre><code>&lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Date", "{0:d}") %&gt;'&gt;&lt;/asp:Label&gt;
  </code></pre>
  
  <p>Can anyone see where I'm going wrong?  Also, can the JS be run when the page loads without using the C# Page_Load method?  I picked up the RegisterStartupScript <a href="http://www.codeproject.com/Questions/200555/How-to-Show-Date-in-Label-using-Javascript.aspx" rel="nofollow">elsewhere</a> but I don't really understand it.</p>
  
  <p>Thanks,
  Liam</p>