问题描述
Hye,
是否可以从后面的代码中将隐藏字段值更改/重置为空字符串?
我尝试了下面的方法但没有工作;
1)hdnKey.Value =
2)Dim hdn As HiddenField = DirectCast(FindControl(hdnKey),HiddenField)
hdn.Value =
谢谢。
----更新1 ----
这是aspx代码:
Hye,
Is it possible to change/reset hiddenfield value to empty string from code behind?
I've tried methods below but none works;
1) hdnKey.Value = ""
2) Dim hdn As HiddenField = DirectCast(FindControl("hdnKey"), HiddenField)
hdn.Value = ""
Thanks.
---- UPDATE 1----
This is aspx codes:
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:HiddenField ID="hdnKey" runat="server" />
<%-- Other controls here --%>
</ContentTemplate>
</asp:UpdatePanel>
*即使我将隐藏字段移到更新面板之外,它仍然没有用。
---更新2 ----
我使用javascript为hiddenfield赋值。
之后,我想将值重置为空字符串。
* Even if i move the hiddenfield outside the update panel, it still didnt work.
--- UPDATE 2 ----
I assign value to hiddenfield using javascript.
After that, I want to reset back the value to empty string.
<script>
document.onkeydown = KeyDownHandler;
document.onkeyup = KeyUpHandler;
var CTRL = false;
var SHIFT = false;
var ALT = false;
var CHAR_CODE = -1;
var confirm_value = document.createElement("INPUT");
var hdnKey = document.getElementById('<%= hdnKey.ClientID %>');
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
var a = hdnKey.value;
function KeyDownHandler(e) {
var x = '';
if (document.all) {
var evnt = window.event;
x = evnt.keyCode;
}
else {
x = e.keyCode;
}
DetectKeys(x, true);
}
function KeyUpHandler(e) {
var x = '';
if (document.all) {
var evnt = window.event;
x = evnt.keyCode;
}
else {
x = e.keyCode;
}
DetectKeys(x, false);
}
function DetectKeys(KeyCode, IsKeyDown) {
if (KeyCode == '16') {
SHIFT = IsKeyDown;
confirm_value.value = "16";
}
else if (KeyCode == '17') {
CTRL = IsKeyDown;
confirm_value.value = "17";
}
else if (KeyCode == '18') {
ALT = IsKeyDown;
confirm_value.value = "";
}
else {
confirm_value.value = "";
}
document.forms[0].appendChild(confirm_value);
document.forms[0].appendChild(hdnKey);
hdnKey.value = confirm_value.value;
}
</script>
推荐答案
这篇关于从后面的代码重置隐藏字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!