Asp.net 在子窗口关闭后更新父窗口上的HiddenField值Javascript,VS2005 c#
我有一个子窗口和一个父窗口,其中有一个hiddenfield HDSelectedFields。我正在更改HDSelectedFields的值 代码:Asp.net 在子窗口关闭后更新父窗口上的HiddenField值Javascript,VS2005 c#,asp.net,javascript,Asp.net,Javascript,我有一个子窗口和一个父窗口,其中有一个hiddenfield HDSelectedFields。我正在更改HDSelectedFields的值 代码: String vStrScript=“function CloseParent(){window.opener.document.getElementById('hdnSelectedFields')。Value=”“+tempstring+”;alert(window.opener.document.getElementById('hdnSel
String vStrScript=“function CloseParent(){window.opener.document.getElementById('hdnSelectedFields')。Value=”“+tempstring+”;alert(window.opener.document.getElementById('hdnSelectedFields')。Value);window.close();}window.opener.document.forms[0]。submit();setTimeout(CloseParent,5);”;
当我关闭窗口时,设置了hdnSelectedFields值,但当我访问父窗口页面Load上的hdnSelectedFields时,它会显示hdnSelectedFields的旧值
如果您在Javascript中看到此警报,则在加载父项完成时,它会显示更新的HDSelectedFields值
任何关于如何访问父页面加载上的HDSelectedFields更新值的建议
Dee您想要的输入框的属性是
值,而不是值首先:您应该选择.
-选择器,因为每个定义的ID必须是唯一的
window.opener.$('#hiddenvariable').val('somevalue');
在弹出窗口中:
$(document).ready(function() {
setTimeout(function() {
var hiddenField = $('#hdnSelectedFields', window.opener);
// you could do some checking here, eg. hiddenField.length for ensuring existance
hiddenField.val('new value');
alert(hiddenField.val()); // for debug reason
window.opener.document.forms[0].submit();
window.close();
}, 5);
});
在你的开场白中:
$(document).ready(function() {
var hiddenField = $('#hdnSelectedFields');
var hiddenFieldValue = hiddenField.val();
alert(hiddenFieldValue); // for debug reason
});
编辑:
你的致命错误如下:
function CloseParent() {
window.opener.document.getElementById('hdnSelectedFields').Value = '" + hdnCheckedAttribute.Value + "';
window.close();
}
window.opener.document.forms[0].submit();
setTimeout(CloseParent, 15);
那么,当你打开弹出窗口时会发生什么?
... 大鼓滚
- 提交表格
- 等待15分钟
- 设置隐藏字段
在pt 1和pt 3之间的某个地方,您的开场白的$(document).ready()
发生了…
缺少pt 3(由于并行性),hiddenField没有设置任何值。
您可能会在弹出窗口的“我的解决方案”中看到我的解决方案,其中说明:
setTimeout(function() {
[...]
window.opener.document.forms[0].submit();
window.close();
}, 5);
我认为这不是问题所在,正如我前面提到的,隐藏字段的值设置正确。但是当父页面加载完成时,它会更新。我想在父页面上检索更新后的值。我想您误解了我的问题。我已成功地从子页面设置了隐藏字段值。问题是在访问父页面时返回。如果在我的脚本中看到返回更新值的警报消息。但是在父级上的后面的脚本没有显示updatesah。。。您可能还没有更新。。。不久前我已经添加了正确的代码/注释!我在asp页面中的按钮提交字符串vStrScript=“function CloseParent(){window.opener.document.getElementById('hdSelectedFields')。Value='“+hdnCheckedAttribute.Value+”;window.close();}window.opener.document.forms[0]。提交();设置超时(CloseParent,15);”;RegisterStartupScript(this.GetType(),“close”,vStrScript);正如您所建议的,我仍然没有得到更新的值。我已经用以下字符串vStrScript=“function CloseParent(){window.opener.document.getElementById('hdnSelectedFields')。value='”“+hdnCheckedAttribute.value+”;window.opener.document.forms[0]。submit();window.close();}setTimeout(CloseParent,5);”; 但我仍然没有得到更新,请不要重复发布。合并。它怎么会断章取义呢。这个ans有什么问题吗?重读这个问题!您的答案不符合任何要求…:(
setTimeout(function() {
[...]
window.opener.document.forms[0].submit();
window.close();
}, 5);