views:

124

answers:

3

I have a child window and a parent window with a hiddenfield hdnSelectedFields .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

A: 

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

Tim Down
I think this is not the problem as I have mentioned above the value of hidden field is set correctly.But it is updated when the parent page is loaded completed.I want to retrieve the updated value on Parent page_load event Dee
Dee
A: 
window.opener.$('#hiddenvariable').val('somevalue');
Yashwant Chavan
- out of context
Andreas Niedermair
How come its out of context. Is any thing is wrong with this ans?
Yashwant Chavan
re-read the question! your answer does not meet any requirement ... :(
Andreas Niedermair
A: 

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);
Andreas Niedermair
I think you have misunderstood my question.I have successfully set the hidden Field value from child.Problem is while accessing back on parent.If you see the alert msg in my script that returns me updated value. but the later script on parent doesn't show updates
Dee
ah ... you probably haven't updated yet ... i've already added proper code/comments some time ago!
Andreas Niedermair
I have put the popup code in asp page something like thison button submit String vStrScript = "<script language=javascript>function CloseParent() {window.opener.document.getElementById('hdnSelectedFields').Value = '" + hdnCheckedAttribute.Value + "';window.close(); } window.opener.document.forms[0].submit(); setTimeout(CloseParent, 15);</script>";ClientScript.RegisterStartupScript(this.GetType(), "close", vStrScript); and opener code as you suggested Still I am not getting updated value.
Dee
see my update!..
Andreas Niedermair
I have updated it with following String vStrScript = "<script language=javascript>function CloseParent() {window.opener.document.getElementById('hdnSelectedFields').Value = '" + hdnCheckedAttribute.Value + "';window.opener.document.forms[0].submit();window.close(); }setTimeout(CloseParent, 5);</script>";But still I don't get updated value
Dee