I'm not really sure what I'm doing wrong. I would like to pass a variable from a JS function to ASP, and then print it in the console at a button click.
JS function:
<script>
function can() {
var candy = "Chocolate";
document.getElementById("Hidden1").value = candy;
}
</script>
ASP.net:
<form id="form1" runat="server">
<div>
<input id="Hidden1" type="hidden" runat="server" />
<asp:Button ID="Button1" runat="server" OnClientClick="can()" Text="Button"
onclick="Button1_Click" />
</div>
</form>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e){
Response.Write(Hidden1.Value);
}
</script>