Stop Press! This question is misleading; the code below works; the problem is unrelated. Please vote to delete. For those interested I had a self-closing <div/> that Chrome didn't like. It works fine with a <div> and </div>. I don't know if this affects other browsers, yet.
Going round in circles here! I have an asp:HiddenField in my .aspx:
<asp:HiddenField id="Aaargh" runat="server" value="Initial Value" />
It gets rendered like this in the browser:
<input type="hidden" name="Aaargh" id="Aaargh" value="Initial Value" />
I set another value dynamically in javascript:
document.getElementById("Aaargh").value = "Dynamic Value";
alert(document.getElementById("Aaargh").value); // Displays "Dynamic Value"
And then the codebehind.cs:
protected void Submit_Click(object sender, EventArgs e)
{
Trace.Write(Aaargh.Value); // Displays "Initial Value"
}
I have also tried a plain html input type=hidden, but I have exactly the same problem?! I know I haven't written a web site for 15 years but I feel like hidden fields have stopped working in the meantime! Happy to learn of any better ways to pass client generated strings to the server! Thanks.