Click here to Skip to main content
15,867,906 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In asp.net I wish to post a value from a popup back to the parent. I have tried calling the following javascript function which should run the click event code of the button 'btnUpdFromPopUp' which is in my parent aspx:
<script type="text/javascript">
  function RefreshParent()
    {
     window.document.getElementById('btnUpdFromPopUp').click();
     window.close();
    }
</script>

But I get an error message: Microsoft JScript runtime error: 'window.opener.document.getElementById(...)' is null or not an object

Any suggestions
Posted
Updated 4-May-11 18:24pm
v2
Comments
Hemant__Sharma 5-May-11 0:37am    
your code says 'window.document' but your exception says 'window.opener..'? are you sure?

"Right click> View Source"" in webbrowser in the Opener page (i.e. the page in which btnUpdFromPopUp) is added. search for "btnUpdFromPopUp" it should locate you to the input control generated for this button check the ID property of the button is it exactly "btnUpdFromPopUp" or "parentOfbutton_btnUpdFromPopUp".

Asp.net appends parentIDs to their child controlIDs in order to make them unique and your code probably fails because you trying to find partial ID and that doesn't exists.

one workaround could be:

1- write a javascript function in your Opener page like below:
function RefreshMe()
    {
      document.getElementById('<%= btnUpdFromPopUp.ClientID %>').click();
    }


2- and modify the child window like this:
C#
function RefreshParent()
    {
     window.opener.RefreshMe();
     window.close();
    }


Hope it will help you.
thanks,
Hemant
 
Share this answer
 
Thanks Hemant, you pointed me in the right direction with looking at the source, when I replaced btnUpdFromPopUp with ctl00_ContentPlaceHolder1_btnUpdFromPopUp I got rid of the error message.

I still have a slight problem in that the session value is not being set and therefore passed to the click event of the parent

I have the following in my popup

Protected Sub editValue_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles editValue.TextChanged
Session("sessionValue") = Me.editValue.Text ' required by Parent
End Sub


and the following in my parent

Protected Sub btnUpdFromPopUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Handles btnUpdFromPopUp.Click
Me.editParentValue.Text = Session("sessionValue")
End Sub

I can see with breakpoints in my code the btnUpdFromPopUp_Click executes but there the new value entered in the popup is not in Session("sessionValue"), but the previous value is !

Any ideas ?
 
Share this answer
 
Comments
Hemant__Sharma 5-May-11 7:11am    
Hello,
First - i'm glad that the suggestion worked.

Second - i request you to add seperate question in seperate thread, because
1- If i'm not able to solve your problem others may not come to your question because it's answered and the title is misleading for your new problem.
2- when other people are looking for similar solution the Title of the problem gets displayed by search engines and again they wont be hitting it because of title.

finally - is editValue_textChanged event is getting fired in popup window? because if that is getting fired than the session value should get set.

Thanks,
Hemant

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900