admin管理员组文章数量:1356808
I have some JavaScript that sets the value of a HiddenField
and then forces a postback. I can trace through this JavaScript and it appears to work correctly. However, when I test the value of the HiddenField
from the page's Load event, it is no longer set.
Searching the web, I see a lot of posts about losing HiddenField
values but none of them seemed to be doing the same thing that I am.
Here's my JavaScript function (modified):
function EditItemItem(itemId) {
document.getElementById('<%= EditItemId.ClientID %>').value = itemId;
__doPostBack('<%= EditItemUpdatePanel.ClientID %>', '');
}
And here's part of my markup (modified):
<div id="EditItemBox" runat="server">
<asp:HiddenField runat="server" id="EditItemId" />
<asp:UpdatePanel ID="EditItemUpdatePanel" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="EditItemPanel" runat="server"
CssClass="ModalDialog" style="display:none;">
<div>Edit an Item</div>
<!-- ... -->
</asp:Panel>
</asp:UpdatePanel>
</div>
Does anyone have any ideas?
I have some JavaScript that sets the value of a HiddenField
and then forces a postback. I can trace through this JavaScript and it appears to work correctly. However, when I test the value of the HiddenField
from the page's Load event, it is no longer set.
Searching the web, I see a lot of posts about losing HiddenField
values but none of them seemed to be doing the same thing that I am.
Here's my JavaScript function (modified):
function EditItemItem(itemId) {
document.getElementById('<%= EditItemId.ClientID %>').value = itemId;
__doPostBack('<%= EditItemUpdatePanel.ClientID %>', '');
}
And here's part of my markup (modified):
<div id="EditItemBox" runat="server">
<asp:HiddenField runat="server" id="EditItemId" />
<asp:UpdatePanel ID="EditItemUpdatePanel" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="EditItemPanel" runat="server"
CssClass="ModalDialog" style="display:none;">
<div>Edit an Item</div>
<!-- ... -->
</asp:Panel>
</asp:UpdatePanel>
</div>
Does anyone have any ideas?
Share Improve this question edited Jun 14, 2011 at 19:55 Jonathan Wood asked Jun 14, 2011 at 19:45 Jonathan WoodJonathan Wood 67.4k82 gold badges304 silver badges531 bronze badges 2- Jonathan. Did you get it working in the end? – marto Commented Jun 20, 2011 at 9:16
- @marto: Not quite. It appears to have something to do with the dynamically loaded user control. I was actually able to better define the problem and even reproduce the issue in a small test project. I've posted a new question here. – Jonathan Wood Commented Jun 20, 2011 at 15:10
2 Answers
Reset to default 6It's easier if you remove runat=server
from the hidden field and then access it from the Form paramaters Request.Form["EditItemId"]
. Then it works every time.
Your code will bee:
function EditItemItem(itemId) {
document.getElementById('EditItemId').value = itemId;
__doPostBack('<%= EditItemUpdatePanel.ClientID %>', '');
}
<div id="EditItemBox" runat="server">
<input type="hidden" id="EditItemId" name="EditItemId" value="" />
<asp:UpdatePanel ID="EditItemUpdatePanel" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="EditItemPanel" runat="server"
CssClass="ModalDialog" style="display:none;">
<div>Edit an Item</div>
<!-- ... -->
</asp:Panel>
</asp:UpdatePanel>
</div>
If you're expecting the value upon an AJAX post-back via the UpdatePanel
then you need to put it inside the ContentTemplate
...
本文标签: javascriptHiddenField Value Lost on PostbackStack Overflow
版权声明:本文标题:javascript - HiddenField Value Lost on Postback - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743954179a2567835.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论