开发者

Update HiddenFiled value on parent window after child window is close Javascript,VS2005 c#

开发者 https://www.devze.com 2022-12-18 16:06 出处:网络
I have a child window and a parent window with a hiddenfield hdnSelected开发者_开发知识库Fields .I am changing the value of hdnSelectedFields.

I have a child window and a parent window with a hiddenfield hdnSelected开发者_开发知识库Fields .I am changing the value of hdnSelectedFields.

Code:

String vStrScript = "<script language=javascript>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);</script>";

When I close the window the hdnSelectedFields value is set but when I access the hdnSelectedFields on parent window pageload it shows old value of hdnSelectedFields.

if you see the alert in JavaScriptit shows updated hdnSelectedFields value when parent is loaded completed.

Any suggestion how can I access hdnSelectedFields updated value on parent pageload.

Dee


The property of the input box you want is value, not Value.


first of all: you should go for the #-selector, as ids must be unique per definition!

in your popup:

$(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);
});

in your opener:

$(document).ready(function() {
    var hiddenField = $('#hdnSelectedFields');
    var hiddenFieldValue = hiddenField.val();
    alert(hiddenFieldValue); // for debug reason
});

edit:
your fatal mistake is following:

function CloseParent() {
    window.opener.document.getElementById('hdnSelectedFields').Value = '" + hdnCheckedAttribute.Value + "';
    window.close();
}
window.opener.document.forms[0].submit();
setTimeout(CloseParent, 15);

so, what will happen when you open the popup? ... biiig drum roll!

  • submit the form
  • wait 15ms
  • set the hiddenField

somewhere in between pt 1 and 3 your $(document).ready() of your opener happens ...
missing pt 3 (due to parallelism), no value is set to the hiddenField. you might see my workaround in my solution for your popup, which states:

setTimeout(function() {
    [...]
    window.opener.document.forms[0].submit();
    window.close();
}, 5);


window.opener.$('#hiddenvariable').val('somevalue');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号