Hi, I was working on small application and I had a requirement as described here. I was creating a page in wjich user can add multiple cotact detail for him. The page has facility for add, delete and edit the contact. I was storing all these information in view state and finally on Save All button adding them to database. Afte the page is completed client has requested that user can have option to select contacts from database also. So I have to open a popup from which user can select multiple contacts and once user click on "Select" button on popup all the selected contacts should be available in grid on main page along with the contacts user has added manually.
To achieve this I need have added hidden field on parent page and on child page I access that hidden field to set the IDs of selected contacts. Once the selected IDs are available on parent window, I need to postback the page so that I can take all the data for those IDs from database and add it to grid for edit or save.
I was knowing that I can set "locationhref" of parent window in child window and then close child window. However this will redirecr the parent page to new location (here new location is same page) but we loose viewstate data. This solution does not work in my case.
// Set parent window's hidden field value from child window
window.opener.document.getElementById(Client ID of Hidden Field).value = Selected IDs;
// raise button click event of parent window
window.opener.document.getElementById(Client ID Of Button).click();
// Close the child window
I had written this script on child page. Tis will raise button click event and in post back I wrote the logic of retrieving data from database for IDs set in hidden field and displayed them in grid.
alert("This is parent window's alert function.");
window.opener.document.getElementById("HiddenField1").value = document.getElementById("TextBox1").value;
Take two buttons on child window. C all "SetParentWindowsHiddenFieldValue" on click of one button and call "CallParentWindowFunction" on click of second button and see the result.