Reputation: 5435
I've tried both of these:
<asp:HiddenField ID = "selectedHour" runat="server" Value="blahblah" />
<input type="hidden" id="myHour" name="hour" Value="blahblah" runat="server"/>
And I try to update it with Javascript:
<script type="text/javascript">
function addEventByClick(hour) {
document.getElementById("myHour").Value = hour;
alert(document.getElementById("myHour").Value);
document.getElementById("dummyButton").click();
}
</script>
which "works": the alert gives me the correct number.
Then, when I click submit it calls a C# method (called by clicking an asp.net component), which does this:
String h = myHour.Value;
//or
//String h = Request.Form["myHour"];
and this always returns "blahblah", that is, the initial value.
All of this stuff is in an update panel, but it's in the SAME update panel, all within the same ContentTemplate.
So why isn't it updating?
Edit: Thanks guys. I hate when I get 3 perfect answers, how do I know which one to check...
Upvotes: 3
Views: 3571
Reputation: 17427
javascript is not case-sensitive. try:
replace document.getElementById("myHour").Value = hour; by
document.getElementById("myHour").value = hour; and
document.getElementById("myHour").Value by
document.getElementById("myHour").value
Upvotes: 2
Reputation: 67802
Try using value
instead of Value
. Browsers are picky about these things.
Alternatively, use jQuery, and your problems magically disappear:
$('#myobject').val( 'new value' );
Upvotes: 3
Reputation: 6684
try with uncapitalized Value, for the raw html:
document.getElementById("myHour").value = hour
Upvotes: 2