admin管理员组文章数量:1391981
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 ponent), 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...
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 ponent), 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...
Share Improve this question edited Jun 9, 2011 at 18:39 Jeremy asked Jun 9, 2011 at 18:25 JeremyJeremy 5,43315 gold badges53 silver badges82 bronze badges 3-
What does this do? ->
document.getElementById("dummyButton").click()
– R1234 Commented Jun 9, 2011 at 18:35 - @Rohan It simulates clicking a button, and works perfectly. I'm using it to open a modal pop-up since there's multiple ways of the user getting that pop-up. – Jeremy Commented Jun 9, 2011 at 18:39
-
not sure though because
.click()
should technically work on a jquery object not on a DOM object as you have selected. – R1234 Commented Jun 9, 2011 at 18:41
3 Answers
Reset to default 3Try using value
instead of Value
. Browsers are picky about these things.
Alternatively, use jQuery, and your problems magically disappear:
$('#myobject').val( 'new value' );
try with uncapitalized Value, for the raw html:
document.getElementById("myHour").value = hour
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
本文标签: cValue of a HiddenField not updatingStack Overflow
版权声明:本文标题:c# - Value of a HiddenField not updating - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744644401a2617310.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论