Passing value from JScript to ASP.NET Control
<p>I am trying to pass a value from a JScript function to an ASP.NET Control but I am not able to make it work. What am I doing wrong here:</p>

<p>aspx.cs</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication5._Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script type="text/javascript"&gt;
        function saveMyData() {
            var myData = "TestData";
            var hiddenInput = document.getElementById('&lt;%=HiddenField1.ClientID %&gt;');
            hiddenInput.Value = myData;
        }
    &lt;/script&gt;

&lt;/head&gt;
&lt;body onload="javascript:saveMyData();"&gt;
    &lt;form id="form1" runat="server"&gt;
        &lt;div&gt;
            &lt;asp:HiddenField ID="HiddenField1" runat="server" /&gt;
            &lt;br&gt;&lt;input type="submit" value="Press Me!"&gt;&lt;br&gt; &lt;--New Code
        &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;

&lt;/html&gt;
</code></pre>

<p>Code Behind:</p>

<pre><code>using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace WebApplication5
{
    public partial class _Default : Page
    {
        protected HtmlInputHidden HiddenField;

        protected void Page_Load(object sender, System.EventArgs e)
        {
            string value = HiddenField1.Value;
        }
    }
}
</code></pre>

<h1>**UPDATE**</h1>

<p>I added in a Submit button but I am still not able to assign the myData Value to the Hidden Control, any thoughts?</p>
