title: getElementById().value in JS, C#, and ASP.NET
body: <p>I tried to get C# and JS to communicate each other through a hidden input. I looked a various forums and codes, but none of them seems to have this exact problem. Many of them had syntax error, and I have tried to debug that. It's mainly the line </p>
  
  <pre><code>document.getElementById("Hidden1").value = str;  
  </code></pre>
  
  <p>that doesn't seem to be working. I have tried putting alert messages before and after that line. Putting the alert before causes the alert to pop up, but putting it after doesn't cause it to pop-up which makes me suspect this line of code even more. No error messages were displayed when I ran it in Visual Studio 2010 through Chrome browser. If anyone can help with it at all, it'd be greatly appreciated.</p>
  
  <p>If I remove the updatepanels, it still wouldn't work. It was actually what I tried at first, but I thought it might've been when the site refreshed during the button click, so I tried implementing the AJAX updatepanel property.</p>
  
  <p><strong>ASP.NET CODE</strong></p>
  
  <pre><code>&lt;%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"     AutoEventWireup="true"
      CodeBehind="Default.aspx.cs" Inherits="WebApplication10._Default" %&gt;
  
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
  
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
    &lt;asp:ScriptManager ID="ScriptManager1" runat="server"/&gt;
    &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt;
  &lt;Triggers&gt;
  
   &lt;asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /&gt;
               &lt;/Triggers&gt;
               &lt;ContentTemplate&gt;
      &lt;div&gt;
          &lt;input id="Hidden1" type="hidden" name="Hidden1" runat="server"    value="replaceme"     /&gt;
          &lt;asp:Button ID="Button1" runat="server" OnClientClick="abc()"  Text="Button" 
              onclick="Button1_Click" /&gt;
      &lt;/div&gt;
      &lt;div&gt;
      &lt;/ContentTemplate&gt;
       &lt;/asp:UpdatePanel&gt;
      &lt;script type="text/javascript"&gt;
          function abc() {
              var str = "value";
              document.getElementById("Hidden1").value = str;  
          }
  &lt;/script&gt;
  &lt;/div&gt;
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>C# CODE</strong></p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
      {
  
          MessageBox.Show(Hidden1.Value);
      }
  </code></pre>