Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

How to check whether control/ function of parent page exists or not from popup window in asp.net using javascript when window.open() used.
Posted
Updated 17-Oct-14 0:01am
v2
Comments
Sinisa Hajnal 17-Oct-14 6:18am    
Having title and text of the question doesn't make it clearer.
What do you mean if parent page exists? Are you asking how to detect if the calling page is still opened? Or how to get the control from master page? Or how to get the control from calling page?

Also, state clearly what have you tried before coming here.
Baroor 17-Oct-14 6:27am    
let say say in Parent.aspx i have txtName
i used window.open() in parent page to pop up childpage.aspx to return some value to parent,
before returning i want to check whether textbox of parent is really there or not.
Sinisa Hajnal 17-Oct-14 7:07am    
How could it NOT be there? If it renders with the page and you used page object to create the window it has to be there, right? If someone closes parent window there will be nothing to show so again it is not releveant what your dialog returns.
Baroor 17-Oct-14 7:09am    
@Sinisa Hajnal,
Im asking how to check at child window??????????
Sinisa Hajnal 17-Oct-14 7:12am    
Yes, I understand that, but I asked why (although I see now that it is not really clear :) sorry about that) ? How will it affect your dialog if it is NOT there?

You can find you're parent window via window.parent

You can chech for existense of the function just like you could on the window object.
 
Share this answer
 
Parent page

XML
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtName" ClientIDMode="Static" runat="server" />
    </div>
    </form>

    <script type="text/javascript">
        window.open("ChildPage.aspx");
    </script>
</body>


Child page

XML
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
    <script type="text/javascript">
        if (window.opener) {
            var txt = window.opener.document.getElementById("txtName");

            if (txt) {
                txt.value = "Hello from child";
            }
        }
    </script>
</body>


Note that this will work in Chrome and FireFox, but it will only work in IE if the site is in non-protected mode. If the site is a local intranet it should be in non-protected mode automatically, but if not you'll have to add the site to your list of trusted sites. To pre-empt your next questions, no you can't do this without that being configured, and no you can't force IE to trust your site.
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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